【问题标题】:How to initialize Spring container through apache tomcat如何通过apache tomcat初始化Spring容器
【发布时间】:2013-10-10 06:50:08
【问题描述】:

除了通过 servlet,我们还有其他方法可以在 Apache tomcat 中初始化 Spring 容器。

谢谢, 废话

【问题讨论】:

  • 请添加一些上下文,你想达到什么目的?

标签: spring tomcat


【解决方案1】:

只需尝试您最喜欢的搜索引擎来获取春季教程。 有很多,我敢肯定它们中的大多数都是在没有网络服务器的情况下开始的。

例如:直接在代码中创建弹簧上下文:

ApplicationContext ApplicationContext ctx = new ClassPathXmlApplicationContext ("META-INF/spring/app-context.xml");
SomeBean bean = ctx.getBean(...);

【讨论】:

  • 谢谢...但我只需要通过 tomcat 启动它。
【解决方案2】:

ServletContextListener 在我看来是最简单的方法。作为奖励,在最新版本的 tomcat 中,您可以使用此侦听器注册由 Spring 本身初始化的额外 servlet。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多