xml配置文件基础

在开发过程中使用到web.xml或者application.xml两个比较常用的xml配置文件,在使用web.xml的时候一般是IDE工具就帮我们生成好了,所有只需要在里面添加自己需要使用的listener,filter等,而application.xml一般不是使用IDE工具生成,但是很多时候都是去别的地方COPY过来,然后直接在里面添加自己需要的bean等,从来就没关注过这些xml配置文件的组成,这里做过记录。
下面用application.xml为例子:

<?xml version="1.0" encoding="UTF-8"?> 
    <!--xmlns是指application.xml文件用到的命名空间,spring的默认命名空间 -->
<beans xmlns="http://www.springframework.org/schema/beans"  
       <!--xmlns:xsi是指application.xml文件遵守xml规范  -->
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       <!--为每个命名空间指定具体的schema文件  -->
       xsi:schemaLocation="http://www.springframework.org/schema/beans                      
                           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
        
        <bean class="org.service.Test" init-method="initData"></bean>
</beans>

在spring3.0在web.xml当中的配置
<listener> 
     <description>Spring core configuration</description> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener>

    <context-param>
   <param-name>contextConfigLocation</param-name>
             <!--默认读取该路径下面的XML文件 -->
   <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

猜你喜欢

转载自qingcyangg.iteye.com/blog/1825001
今日推荐