spring配置xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 该 BeanPostProcessor 将自动对标注 @Autowired 的 Bean 进行注入 -->
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>

<bean id="ctx" class="util.ApplicationContextHelper"></bean>

<context:component-scan base-package="bean.core"></context:component-scan>

<!-- 使用spring自带的占位符替换功能 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<!-- 允许JVM参数覆盖 -->
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
<!-- 忽略没有找到的资源文件 -->
<property name="ignoreResourceNotFound" value="true"/>
<!-- 配置资源文件 -->
<property name="locations">
<list>
<value>classpath:db.properties</value>
<value>classpath:config.properties</value>
</list>
</property>
</bean>

<bean id="dataSource_MSSQL" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<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="initialPoolSize" value="5"></property>
<!-- 最大空闲时间 -->
<property name="maxIdleTime" value="30"></property>
<!-- 最多有多少个连接 -->
<property name="maxPoolSize" value="10"></property>
<!-- 每次最多可以执行多少个批处理语句 -->
<property name="maxStatements" value="50"></property>
<property name="acquireIncrement" value="5"></property><!-- 如果池中数据连接不够时一次增长多少个 -->
<!--关闭连接后不自动commit -->
<property name="autoCommitOnClose" value="false" />
<property name="maxStatementsPerConnection" value="5"></property>
</bean>

<!--<bean id="dataSource_SQLSERVER" class="com.mchange.v2.c3p0.ComboPooledDataSource">-->
<!--<property name="driverClass" value="${jdbc.driver4}" />-->
<!--<property name="jdbcUrl" value="${jdbc.url4}" />-->
<!--<property name="user" value="${jdbc.username4}" />-->
<!--<property name="password" value="${jdbc.password4}" />-->
<!--</bean>-->

<bean id="dataSource_MYSQL" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver2}" />
<property name="jdbcUrl" value="${jdbc.url2}" />
<property name="user" value="${jdbc.username2}" />
<property name="password" value="${jdbc.password2}" />
</bean>

<!-- 暂时先不配置oracle数据库 -->
<!-- <bean id="dataSource_ORACLE" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver3}" />
<property name="jdbcUrl" value="${jdbc.url3}" />
<property name="user" value="${jdbc.username3}" />
<property name="password" value="${jdbc.password3}" />
</bean> -->

<!-- 数据库连接池 -->
<bean id="dataSource" class="bean.core.DynamicDataSource">
<property name="targetDataSources">
<map key-type="java.lang.String">
<entry value-ref="dataSource_MSSQL" key="mssql" />
<entry value-ref="dataSource_MYSQL" key="mysql" />
<!--<entry value-ref="dataSource_SQLSERVER" key="sqlserver" />-->
<!-- <entry value-ref="dataSource_ORACLE" key="oracle" /> -->
</map>
</property>
<!-- 默认使用productDataSource的数据源 -->
<property name="defaultTargetDataSource" ref="dataSource_MSSQL" />
</bean>


<!-- 配置sqlsessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--加载mybatis配置文件-->
<property name="configLocation" value="classpath:SqlMapConfig.xml"></property>
<property name="dataSource" ref="dataSource"></property>
</bean>

<!--需要时放开即可, 整合mybatis -->
<bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
<property name="basePackage" value="mapper"></property>
</bean>

<context:component-scan base-package="service"></context:component-scan>

<!-- 多部分文件上传 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="104857600" />
<property name="maxInMemorySize" value="4096" />
<property name="defaultEncoding" value="UTF-8"></property>
</bean>
<!-- SpringMVC在超出上传文件限制时,会抛出org.springframework.web.multipart.MaxUploadSizeExceededException -->
<!-- 该异常是SpringMVC在检查上传的文件信息时抛出来的,而且此时还没有进入到Controller方法中 -->
<bean id="exceptionResolver"
class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<!-- 遇到MaxUploadSizeExceededException异常时,自动跳转到/WEB-INF/jsp/error_fileupload.jsp页面 -->
<prop key="org.springframework.web.multipart.MaxUploadSizeExceededException">error_fileupload</prop>
</props>
</property>
</bean>

</beans>

原文地址:https://www.cnblogs.com/hexiaofei/p/13472544.html