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

2019-06-18  本文已影响0人  塔塔斯坦

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

2. 在方法中创建IoC容器

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

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

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

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

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

上一篇 下一篇

猜你喜欢

热点阅读