I want to use two different Spring web contexts , each of which has its own contextConfig, Spring servlet and filter, which should be mapped to different URLs. I have
- Standard Grails project mapped to '/'
- And the existing Spring webapp that I want to map to
/extra/
I know that I can deploy both in the same Tomcat, but I am looking for a way to make one application (one war , etc.), since it can simplify the process of deployment and development.
These applications should not use beans or anything else, should be completely separated. Both have DispatcherServlet and DispatcherFilter (and both use Spring Security, but a different configuration)
How can I customize web.xml for such a webapp?
I tried to add a new filter:
<filter> <filter-name>extraSpringSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> <init-param> <param-name>contextAttribute</param-name> <param-value>org.springframework.web.servlet.FrameworkServlet.CONTEXT.extraSpring</param-value> </init-param> <init-param> <param-name>targetBeanName</param-name> <param-value>extraSecurityFilterBean</param-value> </init-param> </filter> <filter-mapping> <filter-name>extraSpringSecurityFilterChain</filter-name> <url-pattern>/extra/*</url-pattern> <dispatcher>FORWARD</dispatcher> <dispatcher>REQUEST</dispatcher> </filter-mapping>
and Spring dispatcher servlet:
<servlet> <servlet-name>extraSpring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> <init-param> <param-name>springConfigLocation</param-name> <param-value>classpath:extra-spring-web.xml</param-value> </init-param> </servlet>
Where:
- two xml contexts in the classpath (inside the exra library library):
- extra-spring -web.xml
- extra- spring -security.xml ( !!! how to configure it?)
- extra-spring -security.xml
- pretty standard spring security configuration
- configured bean
extraSecurityFilterBean - have beans dependency on -web context (but this is not required)
Now it works midnight:
- as I can see from the logs, the
extraSpring servlet successfully loads beans from extra-spring-web.xml - but after accessing url /
/extra/ I got a NoSuchBeanDefinitionException : No bean named "extraSecurityFilterBean" is defined.
So the question is, how can I define the context for DelegatingFilterProxy ? I even tried adding these files to the main context (contextConfigLocation param), this is not what I am looking for, but it did not work.
I looked at the sources of DelegatingFilterProxy, but it is not clear to me how it loads the context.
Igor Artamonov
source share