Spring的xml加載方式

一:類加載方式即調用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>  
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章