Is there a way that a context can be loaded using web.xml in a Spring MVC application?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
From the spring docs
Spring can be easily integrated into any Java-based web framework. All you need to do is to declare the ContextLoaderListener in your web.xml and use a contextConfigLocation to set which context files to load.
The
<context-param>
:You can then use the WebApplicationContext to get a handle on your beans.
See http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/web/context/support/WebApplicationContextUtils.html for more info
You can also load the context while defining the servlet itself (WebApplicationContext)
rather than (ApplicationContext)
or can do both together.
Drawback of just using WebApplicationContext is that it will load context only for this particular Spring entry point (
DispatcherServlet
) where as with above mentioned methods context will be loaded for multiple entry points (Eg.Webservice Servlet, REST servlet
etc)Context loaded by
ContextLoaderListener
will infact be a parent context to that loaded specifically for DisplacherServlet . So basically you can load all your business service, data access or repository beans in application context and separate out your controller, view resolver beans to WebApplicationContext.You can also specify context location relatively to current classpath, which may be preferable