您的位置:首页 > 编程语言 > Java开发

spring配置文件的概念和加载方式?

2017-07-11 15:02 309 查看
首先声明:ssm框架搭建过程中会用到三个配置文件(文件名随意取)(a)Spring配置文件:applicationContext.xml(b)MVC中的HanlerMapping配置文件,因为比较简单,所以通常直接整合在Spring配置文件applicationContext.xml中。(c)mybatis的配置文件:mybatis-config.xml【mybatis的映射文件与本章无关,不再赘述】这三个配置依个人喜好,可以全部整合在一个xml文件里,也可任意整合到两个xml中,更可以每个单独一个xml文件,只要配置正确即可。(1)applicationContext是Spring的默认配置文件,可以把它看做是一张图纸,用来指导Spring工厂产生bean实例,ioc和bean实例的分发(2)web开发中常用web.xml中的listener(listener加载顺序>servlet)加载aplicationContext.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:conf/applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
(3)而SpringMVC配置文件加载方式直接在web中的servlet里配置就行了
<servlet>
<servlet-name>dispatch</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
</servlet>
<servletMapping>
<servlet-name>dispatch</servlet-name>
<url-pattern>*.do</url-pattern>
</servletMapping>

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: