一:类加载方式即调用JAVA代码来加载XML(允许一次加载多个XML)
String[] configs = {"applicationContext.xml","spring.xml"};
ApplicationContext ctx = new ClassPathXmlApplicationContext(configs);
TestBean testBean= (TestBean) ctx.getBean("testBean");
二:web.XML加载方式
<servlet>
<servlet-name>app</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext*.xml,
/WEB-INF/spring*.xml
</param-value>
</context-param>
<load-on-startup>1</load-on-startup>
</servlet>
本文介绍了两种Spring框架中常用的XML配置文件加载方式:一是通过Java代码加载多个XML配置文件;二是通过web.xml文件配置加载XML配置文件。这些方法是Spring应用初始化的基础。
813

被折叠的 条评论
为什么被折叠?



