【发布时间】:2013-10-10 06:50:08
【问题描述】:
除了通过 servlet,我们还有其他方法可以在 Apache tomcat 中初始化 Spring 容器。
谢谢, 废话
【问题讨论】:
-
请添加一些上下文,你想达到什么目的?
除了通过 servlet,我们还有其他方法可以在 Apache tomcat 中初始化 Spring 容器。
谢谢, 废话
【问题讨论】:
只需尝试您最喜欢的搜索引擎来获取春季教程。 有很多,我敢肯定它们中的大多数都是在没有网络服务器的情况下开始的。
例如:直接在代码中创建弹簧上下文:
ApplicationContext ApplicationContext ctx = new ClassPathXmlApplicationContext ("META-INF/spring/app-context.xml");
SomeBean bean = ctx.getBean(...);
【讨论】:
ServletContextListener 在我看来是最简单的方法。作为奖励,在最新版本的 tomcat 中,您可以使用此侦听器注册由 Spring 本身初始化的额外 servlet。
【讨论】: