1,web.xml中
<!--方式一 在servlet中-->
<servlet>
<servlet-name>spring-config</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/conf/spring-config.xml,/WEB-INF/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!--方式二 配置监听-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext-hibernate.xml,/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
2.使用ClassPathApplicationContext。这个类会自动从classpath目录中加载所有的配置文件,不过这个类好像只适用本地调试时用的。
3.通过一个父配置文件将所有子配置文件导入。
在配置文件中有一个标签import,它能把其它的bean定义配置文件导入到父文件夹中
4.通过FileSystemXmlApplicationContext
FileSystemXmlApplicationContext的构造函数是一个字符串数组这个数组就是保存配置文件的路径
<!--方式一 在servlet中-->
<servlet>
<servlet-name>spring-config</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/conf/spring-config.xml,/WEB-INF/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!--方式二 配置监听-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext-hibernate.xml,/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
2.使用ClassPathApplicationContext。这个类会自动从classpath目录中加载所有的配置文件,不过这个类好像只适用本地调试时用的。
3.通过一个父配置文件将所有子配置文件导入。
在配置文件中有一个标签import,它能把其它的bean定义配置文件导入到父文件夹中
4.通过FileSystemXmlApplicationContext
FileSystemXmlApplicationContext的构造函数是一个字符串数组这个数组就是保存配置文件的路径