Tomcat with Spring

I have a three-tier application hosted on Tomcat; web, service and DAO layers.

How do you integrate Tomcat and Spring? I need to use Spring dependency injection, transaction management, etc.

I can only think of creating an instance of ClassPa thanksmlApplicationContext, but in this way a singleton instance of ApplicationContext is not visible between the layers.

+6
spring tomcat
source share
1 answer

If you are building a web application, you are not using ClassPathXmlApplicationContext . Instead, you use the functions of the web container.

You define the context of the application in web.xml .

 <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> 

For more information, see the documentation Specific ApplicationContext for Web Applications .

If the bean needs an instance of the application context, use the ApplicationContextAware interface.

+20
source share

All Articles