Spring在web开发中的应用

1.,在web项目中要使用spring需要导入一个jar包
2.在web.xml文件中配置Listener
这个ContextLoaderListener它实现了ServletContextListener
在这个listener中,当服务器启动时,将ApplicationContext对象,其实是它的一个实现类
WebApplicationContext,对象存入到了ServletContext中。
3. 我们还需要在 web.xml 文件中配置 applicationContext.xml 文件的位置
        默认情况下会在WEB-INF目录 下查找applicationContext.xmls
        如果applicationContext.xml文件不是在默认位置,我们可以在web.xml文件中配置
Classpath:applicationContext.xml 它代表的是在当前工程的类路径下(可以理解成是在src)下来查找applicationContext.xml文件。
contextConfigLocation它是在listener中声明的一个常量,描述的就是spring配置文件的位置。

猜你喜欢

转载自blog.csdn.net/qq_40208605/article/details/80770005