Reputation: 399
I have an issue with mvc:resources
My main-servlet.xml
**
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="50000000" />
</bean>
<mvc:resources mapping="/images/**" location="/images/" />
<mvc:resources mapping="/css/**" location="/css/" />
**
When I comment the mvc:resources
lines everything (else) starts working magically. But when I uncomment the lines, ONLY the resources work. While compiling, log says that ONLY css/** and images/** were mapped and that there is no other mapping.
Web.xml File :
<servlet-mapping>
<servlet-name>main</servlet-name>
<url-pattern>/css/**</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>main</servlet-name>
<url-pattern>/images/**</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>main</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
I tried putting 2 dispatcher servlets but that doesn't working either. The other servlet gets read and does get mapped but the request defaults to the main servlet.
Compilation log AFTER commenting /css/** and /images/** from web.xml :
**
org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/images/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
Nov 26, 2013 11:40:40 AM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/css/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#1'
Nov 26, 2013 11:40:40 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'resources': initialization completed in 220 ms
Nov 26, 2013 11:40:40 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'main'
Nov 26, 2013 11:40:40 AM org.springframework.web.servlet.FrameworkServlet initServletBean
**
INFO: FrameworkServlet 'main': initialization completed in 234 ms
Nov 26, 2013 11:40:40 AM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Nov 26, 2013 11:40:40 AM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Nov 26, 2013 11:40:53 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/KT/] in DispatcherServlet with name 'main'
Upvotes: 0
Views: 7208
Reputation: 399
The question has already been answered but I ran into a bunch of issues while solving it so I wanna leave a few resolution steps just in case someone comes looking with similar problems :
1st and initial issue : mvc:resources what misbehaving (details in question) Solution : Solved exactly as the accepted answer suggested. (
2nd Issue (see 1st stack trace) : Occurs when you don't have a closing tag for ) Solution : add " / " at the end or add right after (also the accepted answer has it correct)
3rd Issue (2nd (last) stack trace) : Occurrs when you don't have the following dependency :
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.3.1.Final</version>
</dependency>
Also. If you're using Tika & Solrj togather, select the sl4j-api with the higher version. Selecting the lower version causes a whole bunch of other problems (sorry no stack trace).
My versions : Solr 3.6.2, Solrj 4.4.0, Tika 1.4.
Upvotes: 0
Reputation: 280175
Note that none of your controllers will be registered with your current setup. You need to add
<mvc:annotation-driven />
to your context so that Spring registers them with the DispatcherServlet
.
Your main
DispatcherServlet
should also simply be mapped to
<servlet-mapping>
<servlet-name>main</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
The others are redundant.
Upvotes: 3