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: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-2.5.xsd
   http://www.springframework.org/schema/aop
   http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
   http://www.springframework.org/schema/tx
   http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-2.5.xsd"
       default-lazy-init="false"
>

<!-- 定义数据源1 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver"/>
<property name="url" value="jdbc:db2://192.168.61.232:50002/BRMSDB:currentSchema=BILL;"/>
<property name="username" value="brms"/>
<property name="password" value="brms0001"/>
</bean>

<!-- 定义数据源2 -->
<context:property-placeholder location="jdbc.properties"/>
<bean id="dataSource2" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>

<!-- jdbc Template -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dateSource" ref="dateSource"/>
</bean>

<!-- session Factory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactory>
<property name="dataSource" ref="dateSource"/>
<property name="packagesToScan">
<list><value>com.*.*.model</value></list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
</bean>

<!-- transaction Manager -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransaction">
<property name="dataSource" ref="dateSource"/>
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<!-- dao level: @Component @Controller @Service @Repository -->
<context:component-scan base-package="com.*.*.dao"/>

<!-- service level: @Transaction + @Component、@Controller、@Service、@Repository -->
<context:component-scan base-package="com.*.*.service/>

<!-- 1、基于XML的事务配置方式 -->
<aop:config>
<aop:pointcut id="transactionPointcut" expression="execution(* com.service..*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="transactionPointcut"/>
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" propagation="NOT_SUPPORTED" />
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<!-- 2、使用注解方式配置事务 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>

你可能感兴趣的:(spring,Web,xml,bean,jdbc)