Tomcat与Spring

Wil*_*kar 6 spring tomcat

我在Tomcat中托管了一个3层appln; 网络,服务和DAO层.

你如何整合Tomcat和Spring?我需要利用Spring的依赖注入,事务管理等.

我只能想到实例化一个ClassPathXmlApplicationContext,但这样,ApplicationContext单例实例在各层之间是不可见的.

提前致谢.

最好的祝福

amr*_*mra 20

如果您要创建Web应用程序,则不要使用ClassPathXmlApplicationContext.而不是你使用web容器的功能.

您定义的应用程序上下文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>
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请查看Web应用程序的便捷ApplicationContext实例化文档.

如果bean需要应用程序上下文的实例,请使用ApplicationContextAwareinterface.