spring 配置文件

来源:互联网 发布:逆战跳高箱子宏数据 编辑:程序博客网 时间:2024/05/17 21:37

applicationContext.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:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd   
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd  
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-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">

<bean id="propertyConfigurer"
         class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:/config/*.properties</value>
<value>classpath:/database/jdbc.properties</value>
            </list>
        </property>
    </bean>


<!-- 使用annotation 自动注册bean,并检查@Required,@Autowired的属性已被注入 -->
<context:component-scan base-package="com.yym">
<context:exclude-filter type ="annotation" expression= "org.springframework.stereotype.Controller" />
</context:component-scan>


<!-- 数据源配置,使用应用内的DBCP数据库连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${db.driverClass}" />
<property name="jdbcUrl" value="${db.jdbcUrl}" />
<property name="user" value="${db.user}" />
<property name="password" value="${db.password}" />
<property name="minPoolSize" value="${db.minPoolSize}" />
<property name="maxPoolSize" value="${db.maxPoolSize}" />
<property name="maxIdleTime" value="${db.maxIdleTime}" />
<property name="initialPoolSize" value="${db.initialPoolSize}" />
<property name="loginTimeout" value="${db.loginTimeout}" />
<property name="checkoutTimeout" value="${db.checkoutTimeout}" />
<property name="idleConnectionTestPeriod" value="${db.idleConnectionTestPeriod}" />
</bean>

<!-- 事物管理配置 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>

<!-- 注解式事务管理 -->
<tx:annotation-driven transaction-manager="transactionManager" />

<!-- 为SqlMap绑定数据源 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:mybatis/mybatis-config.xml" />
<property name="dataSource" ref="dataSource" />
</bean>

<!-- 对应mapper类所在包 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.yym.data.mapper"></property>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>

<import resource="timer.xml"/>
</beans>

0 0
原创粉丝点击