spring 配置文件上面的命名空间和规范复习

Spring配置文件xml头信息解析一html

咱们在使用Spring框架的时候首先要配置其xml文件,大量的头信息到底表明了什么呢,在这里总结下本身的理解。。。

这里是建立web工程时自带的xml文件头内容:java

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
        http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">

这是咱们配置的Spring头信息内容:git

复制代码

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

复制代码

对比之下能够发现存在共性的是他们都有:声明为xml文件,版本为1.0,编码为utf-8,这些你们都容易理解。github

但是xmlns:xsi.......;  xmlns......; xsi:schemaLocation......;这些配置表明了什么东东呢???web

通过总结网上前辈的经验,在这里说一下本身的理解:spring

首先xml是一种严格的标记语言(相对于html来讲),例如必须有结束标签等,另外你们知道,由于其严格的特色,而且能够根据我的的须要增长新的标签内容,常被用来用做项目的配置文件使用。sql

那么须要成为严格的xml标签语言就须要有其规则进行约束,咱们新建的标准的xml文件包含了xmlns:xsi.......;  xmlns......; xsi:schemaLocation.....这些内容如上所示,xmlns=命名空间,xsi=xml-schema-instance(xml模板实例,标准的是这样来命名的,好官方),知道这些咱们就知道标准的web.xml文件内容这些是什么了.express

web.xml的头信息:

1.xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance声明该文件的内容可使用xsi的标签库,api

2.xmlns="http://xmlns.jcp.org/xml/ns/javaee"声明标签的使用范围是被javaee的开发使用的mybatis

3.xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee声明可使用的标签库和对应的具体的标签库版本地址。

那么Spring的头信息也就是:

1.xmlns=http://www.springframework.org/schema/beans表示是spring beans的xml配置文件

2.xmlns:xsi;xmlns:context;xmlns:aop;xmlns:tx;声明可使用标准的xml标签(xsi);也可使用context;aop;tx等声明后的标签库的标签,即声明的xmlns:后的内容能够做为标签规则出如今xml文件中,没有包含在内的使用时会报错(做为一种严格的标记语言的特性)。

3.xsi-schemaLocation这是语法规则契约(xmlns也是;而xmlns:xsi只是声明标签的规则),=等号后面的内容就是引入的具体的标签库和对应的要在文本中使用的标签库具体版本规则的地址。

4.因为在xsi-schemaLocation中定义的是标签的属性等相关信息,xmlns:p中因为p命名空间的引入是为了简化属性property的书写格式,而p的属性是可变的,因此没有在xsi-schemaLocation中定义。

注意:在xsi-schemaLocation中最后一个http:.....与双引号”之间要有一个空格,不然会找不到地址报错。

 

以上,并非全部的规范和命名空间,只要够用就行,下面导入一个本身的

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
		http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
		http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.2.xsd 
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"
       default-lazy-init="true">

    <description>Spring Configuration</description>

    <!-- 定义aspectj -->
    <aop:aspectj-autoproxy/>
    
    <!-- 使用annotation 自动注册bean,并检查@Required,@Autowired的属性已被注入 -->
    <context:component-scan base-package="com.minxin.me.backstage">
        <context:exclude-filter type="annotation"
                                expression="org.springframework.stereotype.Controller"/>
        <context:exclude-filter type="annotation"
                                expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
    </context:component-scan>

    <!-- JSR303 Validator定义 -->
    <bean id="validator" class="com.minxin.me.backstage.commons.validator.MyValidator"/>
    <!-- 加载配置属性文件 -->
    <bean
            class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath*:/sys_config.properties</value>
            </list>
        </property>
    </bean>

	<bean id="tztService" class="com.minxin.me.backstage.platform.yeepayapi.utils.TZTService"></bean>
	
    <!-- PropertiesLoader定义 -->
    <bean id="proputil" class="com.minxin.me.backstage.commons.PropertiesLoader">
        <constructor-arg>
            <list>
                <value>validator-zrmx.properties</value>
                <value>sys_config.properties</value>
            </list>
        </constructor-arg>
    </bean>


    <!-- MyBatis配置 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->
        <property name="typeAliasesPackage" value="com.minxin.me.backstage.core.mapper"/>
        <!-- 显式指定Mapper文件位置 -->
        <property name="mapperLocations" value="classpath:com/minxin/me/backstage/core/**/*Mapper.xml"/>

        <property name="plugins">

            <array>
                <bean class="com.github.pagehelper.PageHelper">
                    <property name="properties">
                        <value>
                            dialect=oracle
                        </value>
                    </property>
                </bean>
            </array>
        </property>
    </bean>


    <!-- 配置自定义的SqlSessionTemplate模板,注入相关配置 -->
    <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate"
          scope="prototype">
        <constructor-arg index="0" ref="sqlSessionFactory"/>
    </bean>

    <!-- 扫描basePackage下全部以@MyBatisRepository标识的 接口 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.minxin.me.backstage"/>
        <property name="sqlSessionTemplateBeanName" value="sqlSessionTemplate"/>
        <property name="annotationClass"
                  value="com.minxin.me.backstage.commons.MyBatisRepository"/>
    </bean>


    <!-- 数据源 -->
     <!-- <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
          destroy-method="close">
        <property name="driverClass" value="${jdbc.driver}"/>
        <property name="jdbcUrl" value="${jdbc.url}"/>
        <property name="user" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <property name="acquireIncrement" value="${c3p0.acquireIncrement}"></property>
        <property name="initialPoolSize" value="${c3p0.initialPoolSize}"></property>
        <property name="maxIdleTime" value="${c3p0.maxIdleTime}"></property>
        <property name="maxPoolSize" value="${c3p0.maxPoolSize}"></property>
        <property name="minPoolSize" value="${c3p0.minPoolSize}"></property>
        <property name="acquireRetryDelay" value="1000"></property>
        <property name="acquireRetryAttempts" value="60"></property>
        <property name="breakAfterAcquireFailure" value="false"></property>
        <property name="maxStatements" value="${c3p0.maxStatements}"></property>
        <property name="maxStatementsPerConnection" value="${c3p0.maxStatementsPerConnection}"></property>
    </bean> -->
    <!-- <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
          destroy-method="close">
        <property name="driverClass" value="oracle.jdbc.driver.OracleDriver"/>
        <property name="jdbcUrl" value="jdbc:oracle:thin:@192.168.9.42:1521:ORA11G"/>
        <property name="user" value="ct_mefc_uta"/>
        <property name="password" value="K7ig0ywuKu"/>
        <property name="acquireIncrement" value="1"></property>
        <property name="initialPoolSize" value="20"></property>
        <property name="maxIdleTime" value="5"></property>
        <property name="maxPoolSize" value="50"></property>
        <property name="minPoolSize" value="5"></property>
        <property name="acquireRetryDelay" value="1000"></property>
        <property name="acquireRetryAttempts" value="60"></property>
        <property name="breakAfterAcquireFailure" value="false"></property>
        <property name="maxStatements" value="0"></property>
        <property name="maxStatementsPerConnection" value="50"></property>
    </bean> -->
	 <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiName"> <value>java:comp/env/jdbc/minxinMeFcDataSource</value>
		</property> </bean>
		
    <!-- 事务 -->
    <bean id="transactionManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <!-- 注解驱动事务管理 -->
    <tx:annotation-driven transaction-manager="transactionManager"/>

    <bean id="transactionInterceptor"
          class="org.springframework.transaction.interceptor.TransactionInterceptor">
        <property name="transactionManager" ref="transactionManager"/>
        <!-- 配置事务属性 -->
        <property name="transactionAttributes">
            <props>
                <prop key="delete*">PROPAGATION_REQUIRED, -Exception</prop>
                <prop key="add*">PROPAGATION_REQUIRED, -Exception</prop>
                <prop key="update*">PROPAGATION_REQUIRED, -Exception</prop>
                <prop key="save*">PROPAGATION_REQUIRED, -Exception</prop>
                <prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
            </props>
        </property>
    </bean>

<!-- 微服务配置开始 -->
	<bean class="com.mx.micro.executor.ExecutorFactory" lazy-init="false">
		<property name="executorMap">
			<map key-type="java.lang.String">
				<entry>
					<key>
						<value>cxf</value>
					</key>
					<ref bean="cxfExecutor"></ref>
				</entry>
			</map>
		</property>
	</bean>
	<bean id="cxfExecutor" class="com.mx.micro.executor.cxf.CXFExecutor" lazy-init="false"></bean>
	<bean class="com.nh.esb.ws.NhEsbClientFactory" init-method="init"  lazy-init="false">
		<!-- <property name="configUrl" value="${nhesb.config.url}"></property> -->
		<!-- <property name="remoteConfigFlag" value="true"></property> -->
		<property name="addressMap4Bean" ref="addressSysB"></property>
	</bean>
	<bean id="addressSysB" class="com.nh.esb.core.NhEsbAddress" lazy-init="false">
		<property name="sysid" value="dicService"></property>
		<property name="ip" value="10.10.23.79"></property>
		<property name="port" value="8080"></property>
		<property name="url"
		value="https://www.minxineseal.com:8443/minxin-eseal/webservice/nhCmdService"></property>
	</bean>
	<!-- 微服务配置结束 -->

	<!-- 从Srping配置文件中根据id读取Bean的工具 -->
    <bean id="springUtil" class="com.minxin.me.backstage.commons.utils.SpringUtil" scope="singleton" />
    <bean class="com.minxin.micro.rule.engine.context.MicroContextHolder" lazy-init="false"></bean>
    <bean class="com.minxin.micro.rule.engine.core.GroovyInitUtil" init-method="initGroovy" lazy-init="false">
        <property name="fileList">
            <list>
                <bean class="com.minxin.micro.rule.engine.core.GFileBean">
                    <property name="ruleStamp" value="true"></property>
                    <property name="jarFileFlag" value="true"></property>
                    <property name="dirFlag" value="true"></property>
                    <property name="rulePath" value="/groovy/"></property>
                </bean>
            </list>
        </property>
    </bean>
</beans>
相关文章
相关标签/搜索