美文网首页
Spring在java web中使用的核心思路

Spring在java web中使用的核心思路

作者: 塔塔斯坦 | 来源:发表于2019-06-18 17:13 被阅读0次

    1. web.xml中配置一个继承了ServletContextListener的listner,并且实现contextInnitialized方法

    2. 在方法中创建IoC容器

    比如创建ClasspathApplicationContext, 还可以通过web.xml中配置应用参数的方式配置spring配置文件的路径。

    创建后的IoC容器放入ServletContext.setAttribute中

    这样applicationContext.xml文件路径也是可以改变的。

    3. 在applicationContext.xml中正常使用spring配置

    在需要用到bean的地方, 先获取ServletContext, 然后。。

    相关文章

      网友评论

          本文标题:Spring在java web中使用的核心思路

          本文链接:https://www.haomeiwen.com/subject/onlmsttx.html