I am trying to map any requests that come to /views/node_modules/* to /resources/angular_resources/* folder in my Spring project. How could I achieve this?
Currently I have applicationContext.xml file that looks the following way:
<context:component-scan
base-package="fomoapp.domain, fomoapp.dao, fomoapp.service" />
<!-- Root Context: defines shared resources visible to all other web components -->
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:resources mapping="/views/node_modules/**" location="/resources/angular_resources/" />
<mvc:default-servlet-handler/>
Full web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/META-INF/spring/applicationContext.xml
classpath*:/META-INF/spring/applicationContext-security.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>fomoapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/fomoapp-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>fomoapp</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/views/node_modules/</url-pattern>
</servlet-mapping>
I tried the solution here: Absolute path in <mvc:resources/> instead of path relative to mapping of spring servlet
But it does not work somehow.
Ultimately solved it. The following thread really helped me: Use of multiple "mvc:resources" tag in spring mvc.
So, I did the following:
<mvc:default-servlet-handler/> from applicationContext.xml and add <mvc:annotation-driven /> at the bottom insteaddefault servlet stuff from web.xmlAfter doing this I was able to add additional mappings to applicationContext.xml. Here it is:
<context:component-scan
base-package="fomoapp.domain, fomoapp.dao, fomoapp.service" />
<!-- Root Context: defines shared resources visible to all other web components -->
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:resources mapping="/views/node_modules/@angular/**" location="/resources/angular_resources/@angular/" />
<mvc:resources mapping="/views/node_modules/rxjs/**" location="/resources/angular_resources/rxjs/" />
<mvc:annotation-driven />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With