I have an angular application which uses ui-router, and is served by a SpringMvc (4.2.4) java app. I decided to map any requests to a single Controller/method which loads the single JSP page of my project.
But, When I try to add static resources mappings, to load js and css files, those static resources are ignored... Every requests, inside the [mayapp]/resources/* path leads to my single jsp page.
Here is my config :
web.xml
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
servlet.xml
<context:component-scan base-package="com.adveasys.omrh.front.web" />
<mvc:annotation-driven></mvc:annotation-driven>
<mvc:resources mapping="/resources/**" location="/resources/">
<mvc:resource-chain resource-cache="false" auto-registration="false">
<mvc:resolvers>
<bean class="org.springframework.web.servlet.resource.GzipResourceResolver"/>
<bean class="org.springframework.web.servlet.resource.PathResourceResolver"/>
</mvc:resolvers>
</mvc:resource-chain>
</mvc:resources>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".jsp" />
</bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".jsp" />
</bean>
MainController.java
@RequestMapping("/**")
public ModelAndView mainPage(HttpServletRequest request) throws JsonProcessingException {
Before having this problem, I used the default servlet in web.xml for every /resources/*, But I am generating a .gz version of my scripts/css with maven and I want this kind of configuration to be able to user the GzipResourceResolver.
Things I already tried, and did not work
Thanks in advance.
Alright, after digging in debug mode. HandlerMappings where in this order :
When calling a /resource/* file the RequestMappingHandlerMapping was the first to respond as a valid candidate.
after adding such an order in Spring configuration :
<mvc:resources mapping="/resources/**" location="/resources/" order = "-1">
It worked.