`

spring常用配置

    博客分类:
  • java
阅读更多
<?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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
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"
>

<!-- 自动AOP代理 -->
<aop:aspectj-autoproxy/>
<context:component-scan base-package="gbits.cstool.transaction,
  gbits.cstool.dao,
  gbits.cstool.service"/>
 
<!-- 引用属性文件 -->
<bean id="propertyLoder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config/datasource.properties</value>
</list>
</property>
</bean>
<!-- 注册数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${dbdriver}"></property>
<property name="url" value="${dburl}"></property>
<property name="username" value="${dbuser}"></property>
<property name="password" value="${dbpwd}"></property>
<property name="minIdle" value="2"></property>
<property name="testOnBorrow" value="true"></property>
<property name="testOnReturn" value="true"></property>
<property name="validationQuery" value="select user()"></property>
<property name="timeBetweenEvictionRunsMillis" value="5000"></property>
<property name="minEvictableIdleTimeMillis" value="28000000"></property>
</bean>
<!-- 配置SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!-- 配置hibernate属性 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${dbdialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.connection.autocommit">${hibernate.connection.autocommit}</prop>
</props>
</property>
<!-- 实体包扫描 -->
<property name="packagesToScan">
<list>
<value>gbits.cstool.entity</value>
</list>
</property>
</bean>
  
<!-- 配置Hibernate模板代码 -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!-- 配置JDBCTemplate -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
</beans>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics