這裏是建立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
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聲明可使用的標籤庫和對應的具體的標籤庫版本地址。
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>