Spring Mvc模块化配置考虑
applicationContext.xml(spring 基础配置文件放在spring包下,web.xml中导入之)
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-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/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<!-- auto register Processor -->
<context:annotation-config/>
<bean id="propertyConfigurer"
class="com.xxx.common.config.GlobalConfigPropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/META-INF/spring/jdbc.properties</value>
<value>classpath:/META-INF/spring/common-mis.properties</value>
<value>classpath:/META-INF/spring/config.properties</value>
<value>classpath:/META-INF/spring/cognos.properties</value>
<value>classpath:/META-INF/spring/client.properties</value>
</list>
</property>
</bean>
<import resource="classpath:META-INF/spring/persistence-ceo.xml"/>
<import resource="classpath:META-INF/spring/dal-dao-ceo.xml"/><!--导入配置文件 dao层依赖注入--->
<import resource="classpath:META-INF/spring/dal-dao-ceo-batch.xml"/>
<import resource="classpath:META-INF/spring/cache-context-mis.xml"/>
<import resource="classpath:META-INF/spring/services-ceo.xml"/>
<!-- system manager start -->
<import resource="classpath:META-INF/spring/persistence-system.xml"/>
<import resource="classpath:META-INF/spring/dal-dao-system.xml"/>
<import resource="classpath:META-INF/spring/dal-dao-system-batch.xml"/>
<import resource="classpath:META-INF/spring/services-system.xml"/>
<!-- system manager end -->
<!-- engine start -->
<!--
<import resource="classpath:META-INF/spring/persistence-engine-test.xml"/>
<import resource="classpath:META-INF/spring/dal-dao-engine.xml"/>
<import resource="classpath:/META-INF/spring/common-core-engine.xml"/>
<import resource="classpath:/META-INF/spring/common-core-lock.xml"/>
<import resource="classpath:/META-INF/spring/common-core-schedule.xml"/>-->
<!-- engine end -->
<!-- security -->
<import resource="classpath:META-INF/spring/spring-security.xml"/>
<!-- <import resource="classpath:META-INF/spring/spring-pre-security.xml"/>-->
<!-- remote -->
<import resource="classpath:META-INF/spring/remote-client.xml"/>
</beans>
persistence-ceo.xml(spring包下,由applicationContext.xml文件import,顾名思义,本配置文件一般无需修改)
<?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: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/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">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>${jdbc.driverClassName}</value>
</property>
<property name="url">
<value>${jdbc.url}</value>
</property>
<property name="username">
<value>${jdbc.username}</value>
</property>
<property name="password">
<value>${jdbc.password}</value>
</property>
<property name="maxWait" value="300000"/>
<property name="maxIdle" value="30"/>
<property name="maxActive" value="100"/>
<property name="testOnBorrow" value="true"/>
<property name="testWhileIdle" value="true"/>
<property name="validationQuery" value="select 1 from dual"/>
</bean>
<bean id="sqlMapClient" class="com.xxx.core.ibatis.IncludesSqlMapClientFactoryBean">
<property name="configLocation" value="classpath:sqlmap/sqlmap-ceo.xml"/>
</bean>
<bean id="misCeoSqlMapClientDAO" abstract="true">
<property name="sqlMapClient" ref="sqlMapClient"/>
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="commonJdbcDao" class="com.xxx..core.dal.daointerface.CommonJDBCDAO">
<property name="jdbcTemplate" ref="jdbcTemplate"></property>
</bean>
<bean id="misJxBaoBiaoDAO" abstract="true">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="threadPool" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="16"/>
<property name="maxPoolSize" value="200"/>
<property name="queueCapacity" value="500"/>
</bean>
</beans>
dal-dao-ceo.xml(spring包下)
<?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:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd"
default-autowire="byName">
<!-- ======================================================================== -->
<!-- DAO -->
<!-- ======================================================================== -->
<bean id="misSeqDAO" class="com.xxx.core.dal.ibatis.IbatisSeqDAO" parent="misCeoSqlMapClientDAO"/>
<!--misCeoSqlMapClientDAO是在application中配置的抽象bean,其中定义了sqlMapClient和dataSource-->
<bean id="alertConfigDAO" class="com.xxx.core.dal.ibatis.IbatisAlertConfigDAO" parent="misCeoSqlMapClientDAO"/>
</bean>