1.annotation方式

<?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:context="http://www.springframework.org/schema/context"
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-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-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">
<context:annotation-config />
<context:component-scan base-package="com.bjsxt" />

<!--
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">

<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/spring" />
<property name="username" value="root" />
<property name="password" value="bjsxt" />
</bean>
-->

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

<bean id="dataSource" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<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>

<bean id="sf"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!--
<property name="annotatedClasses">
<list>
<value>com.bjsxt.model.User</value>
<value>com.bjsxt.model.Log</value>
</list>
</property>
-->
<property name="packagesToScan">
<list>
<value>com.bjsxt.registration.model</value>

</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>

<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sf"></property>
</bean>

<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sf" />
</bean>

<aop:config>
<aop:pointcut id="bussinessService"
expression="execution(public * com.bjsxt.registration.service.*.*(..))" />
<aop:advisor pointcut-ref="bussinessService"
advice-ref="txAdvice" />
</aop:config>

<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="exists" read-only="true" />
<tx:method name="add*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>

</beans>

2.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:context="http://www.springframework.org/schema/context"
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.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:i18n.properties</value>
<value>classpath:DataConnection.properties</value>
<value>classpath:cdsp.properties</value>
<value>classpath:memcache.properties</value>
<value>classpath:jta.properties</value>
</list>
</property>
</bean>
<!-- 数据源配置开始 -->
<!-- 框架默认库 -->
<bean id="dataSource"
class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init"
destroy-method="close">
<property name="uniqueResourceName">
<value>sourceA</value>
</property>
<property name="xaDataSourceClassName">
<value>oracle.jdbc.xa.client.OracleXADataSource</value>
</property>
<property name="xaProperties">
<props>
<prop key="user">${jdbc.username}</prop>
<prop key="password">${jdbc.password}</prop>
<prop key="URL">${jdbc.url}</prop>
</props>
</property>
<property name="maxPoolSize">
<value>60</value>
</property>
<property name="testQuery">
<value>SELECT 1 from dual</value>
</property>
</bean>

<!-- 渠道库 -->
<bean id="chnDataSource"
class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init"
destroy-method="close">
<property name="uniqueResourceName">
<value>chnDataSource</value>
</property>
<property name="xaDataSourceClassName">
<value>oracle.jdbc.xa.client.OracleXADataSource</value>
</property>
<property name="xaProperties">
<props>
<prop key="user">${chn.username}</prop>
<prop key="password">${chn.password}</prop>
<prop key="URL">${chn.url}</prop>
</props>
</property>
<property name="maxPoolSize">
<value>60</value>
</property>
<property name="testQuery">
<value>SELECT 1 from dual</value>
</property>
</bean>

<!-- 多数据源配置结束 -->

<bean id="default" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingLocations">
<list>
<value>classpath:hibernate/*.hbm.xml</value>
<value>classpath:hibernate/*/*.hbm.xml</value>
<value>classpath:hibernate/*/*/*.hbm.xml</value>
<value>classpath:hibernate/*/*/*/*.hbm.xml</value>
<!-- CDSP hibernate配置文件 -->
<value>classpath:cdsp/hibernate/*.hbm.xml</value>
<value>classpath:cdsp/hibernate/*/*.hbm.xml</value>
<value>classpath:cdsp/hibernate/*/*/*.hbm.xml</value>
<value>classpath:cdsp/hibernate/*/*/*/*.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">com.wnlja.prm.baselayer.hibernate.wnljaOracle9Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.jdbc.fetch_size">50</prop>
<prop key="hibernate.jdbc.batch_size">25</prop>
<prop key="hibernate.use_outer_join">true</prop>
<!-- EhCache集成hibernate配置 -->
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
</props>
</property>
</bean>

<bean id="chnSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="chnDataSource"/>
<property name="mappingDirectoryLocations">
<list>
<value>
classpath:hibernate/*.xml,
classpath:hibernate/*/*.xml,
classpath:hibernate/s98D00/*/*/*.xml,
</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">com.wnlja.prm.baselayer.hibernate.wnljaOracle9Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.jdbc.fetch_size">50</prop>
<prop key="hibernate.jdbc.batch_size">25</prop>
<prop key="hibernate.use_outer_join">true</prop>
</props>
</property>
</bean>
<!-- bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="default" />
</property>
</bean-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="query*" read-only="true"/>
<tx:method name="*"/>
<tx:method name="checkUser" no-rollback-for="com.wnlja.prm.baselayer.exception.BusinessException"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="rightManageServicePointcut" expression="execution(* com.wnlja.prm.baselayer.rightmanage.service.*.*(..))"/>
<!-- 增加用户 -->
<aop:pointcut id="addUserPointcut" expression="execution(* com.wnlja.prm.baselayer.rightmanage.service.RightManageService.addUser(..))"/>
<aop:pointcut id="editUserPointcut" expression="execution(* com.wnlja.prm.baselayer.rightmanage.service.RightManageService.editUser(..))"/>
<aop:advisor pointcut-ref="rightManageServicePointcut" advice-ref="txAdvice"/>
<aop:advisor pointcut-ref="rightManageServicePointcut" advice-ref="logAfterAdvice"/>
</aop:config>
<!-- -------------------------------------------------------------------------------------------------------- -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref local="default" />
</property>
<!-- EHCache配置 -->
<property name="cacheQueries">
<value>true</value>
</property>
</bean>

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
<!-- --------------------------------------------------------------------------------------------------------- -->
<bean id="atomikosTransactionManager"
class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init" destroy-method="close">
<property name="forceShutdown">
<value>true</value>
</property>
</bean>

<bean id="atomikosUserTransaction"
class="com.atomikos.icatch.jta.UserTransactionImp">
<property name="transactionTimeout" value="300" />
</bean>

<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager">
<ref bean="atomikosTransactionManager" />
</property>
<property name="userTransaction">
<ref bean="atomikosUserTransaction" />
</property>
</bean>
<!-- ------------------------------------------------------------------------------------------------------------- -->
<bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
<property name="transactionManager">
<!-- <ref bean="transactionManager" /> -->
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="query*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
<prop key="test*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!-- ------------------------------------------------------------------------------------------------------------- -->
<bean id="SpringContextUtil" class="com.wnlja.prm.baselayer.spring.SpringContextUtil" />
<!-- ------------------------------------------------------------------------------------------------------------- -->
<!--
<bean id="imdb" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="imdbDataSource"/>
<property name="mappingDirectoryLocations">
<list>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=com.wnlja.prm.baselayer.hibernate.wnljaIMDBDialect
hibernate.show_sql=true
</value>
</property>
</bean>
-->
<bean id="rightManageService" class="com.wnlja.prm.baselayer.rightmanage.service.RightManageServiceImpl">
<property name="dao" ref="rightManageDao" />
</bean>
<bean id="rightManageDao" class="com.wnlja.prm.baselayer.rightmanage.dao.${dao.impl}.RightManageDaoImpl"/>

<bean id="logQueryService" parent="baseTransactionProxy">
<property name="target">
<bean class="com.wnlja.prm.baselayer.rightmanage.service.LogQueryServiceImp">
<!-- 默认查询的sql/hql -->
<property name="sql">
<value>
</value>
</property>
<!-- 是否是Hql -->
<property name="isHql">
<value>false</value>
</property>
<!-- 是否去掉空条件 -->
<property name="rmEmpty">
<value>true</value>
</property>
<property name="dao" ref="rightManageDao" />
</bean>
</property>
</bean>
<bean id="DBConnection" parent="baseTransactionProxy">
<property name="target">
<bean class="com.wnlja.prm.baselayer.hibernate.DBConnectionImpl">
<property name="sessionFactory" ref="default" />
<property name="sessionFactoryMap" ref="sessionFactoryMap" />
</bean>
</property>
</bean>
<bean id="sessionFactoryMap" class="java.util.HashMap"><!-- 前置的sessionFactory -->
<constructor-arg>
<map>
<entry><key><value>default</value></key><ref bean="default"/></entry>
<entry><key><value>chn</value></key><ref bean="chnSessionFactory"/></entry>
</map>
</constructor-arg>
</bean>

<!-- baseDao -->
<bean id="genericDao" class="com.wnlja.prm.baselayer.hibernate.genericdao.impl.GenericDao">
</bean>

<bean id="genericHBDao" class="com.wnlja.prm.baselayer.hibernate.genericdao.impl.GenericDaoHBImpl">
<property name="sessionFactory">
<ref bean="default" />
</property>
<property name="sessionFactoryMap" ref="sessionFactoryMap" />
</bean>

<bean id="genericJDBCDao" class="com.wnlja.prm.baselayer.hibernate.genericdao.impl.GenericJDBCDaoImpl">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="dataSourceMap" ref="dataSourceMap" />
</bean>
<bean id="dataSourceMap" class="java.util.HashMap">
<constructor-arg>
<map>
<entry><key><value>default</value></key><ref bean="dataSource"/></entry>
<entry><key><value>chn</value></key><ref bean="chnDataSource"/></entry>
</map>
</constructor-arg>
</bean>

<bean id="keyInfo" parent="baseTransactionProxy">
<property name="target">
<bean class="com.wnlja.prm.baselayer.keygen.KeyInfo">
<property name="jdbcTemplate">
<ref bean="jdbcTemplate"/>
</property>
</bean>
</property>
</bean>
<!-- ---------------------------------------------------------------------------------------------------------- -->
<!-- 添加spring 自动填写事务
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<value>*Service,*service</value>
</property>
<property name="interceptorNames">
<list>
<value>logAfterAdvisor</value>
</list>
</property>
</bean> -->
<!--
<bean id="privilegeBeforeAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice">
<ref local="privilegeBeforeAdvice" />
</property>
<property name="pattern">
<value>.*</value>
</property>
</bean>
-->
<!--
<bean id="privilegeBeforeAdvice" class="com.wnlja.prm.baselayer.spring.PrivilegeBeforeAdvice" />
-->

<!--
<bean id="logAfterAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice">
<ref local="logAfterAdvice" />
</property>
<property name="pattern">
<value>.*</value>
</property>
</bean>-->

<bean id="logAfterAdvice" class="com.wnlja.prm.baselayer.spring.LogAfterAdvice" >
<property name="logWriter">
<ref local="logWriter" />
</property>
</bean>

<bean id="logWriter" parent="baseTransactionProxy">
<property name="target">
<bean class="com.wnlja.prm.baselayer.spring.${dao.impl}.LogWriterImpl">
<property name="genericDao" ref="genericDao" />
</bean>
</property>
</bean>
</beans>

spring经典配置的更多相关文章

  1. Spring经典高频面试题,原来是长这个样子

    Spring经典高频面试题,原来是长这个样子 2019年08月23日 15:01:32 博文视点 阅读数 719   版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文 ...

  2. Spring Boot -- 配置切换指南

    一般在一个项目中,总是会有好多个环境.比如: 开发环境 -> 测试环境 -> 预发布环境 -> 生产环境 每个环境上的配置文件总是不一样的,甚至开发环境中每个开发者的环境可能也会有一 ...

  3. spring 定时任务配置

    1.(易)如何在spring中配置定时任务? spring的定时任务配置分为三个步骤: 1.定义任务 2.任务执行策略配置 3.启动任务 (程序中一般我们都是到过写的,直观些) 1.定义任务 < ...

  4. 两种流行Spring定时器配置:Java的Timer类和OpenSymphony的Quartz

    1.Java Timer定时 首先继承java.util.TimerTask类实现run方法 import java.util.TimerTask; public class EmailReportT ...

  5. Spring Cloud 配置服务

    Spring Cloud 配置服务 1. 配置服务简介 产生背景: 传统开发中,我们通常是将系统的业务无关配置(数据库,缓存服务器)在properties中配置,在这个文件中不会经常改变,但随着系统规 ...

  6. spring事务配置详解

    一.前言 好几天没有在对spring进行学习了,由于这几天在赶项目,没有什么时间闲下来继续学习,导致spring核心架构详解没有继续下去,在接下来的时间里面,会继续对spring的核心架构在继续进行学 ...

  7. spring MVC配置详解

    现在主流的Web MVC框架除了Struts这个主力 外,其次就是Spring MVC了,因此这也是作为一名程序员需要掌握的主流框架,框架选择多了,应对多变的需求和业务时,可实行的方案自然就多了.不过 ...

  8. Spring mvc 配置详解

    现在主流的Web MVC框架除了Struts这个主力 外,其次就是Spring MVC了,因此这也是作为一名程序员需要掌握的主流框架,框架选择多了,应对多变的需求和业务时,可实行的方案自然就多了.不过 ...

  9. Spring动态配置多数据源

    Spring动态配置多数据源,即在大型应用中对数据进行切分,并且采用多个数据库实例进行管理,这样可以有效提高系统的水平伸缩性.而这样的方案就会不同于常见的单一数据实例的方案,这就要程序在运行时根据当时 ...

随机推荐

  1. nuxt 头部引入js文件 第一次进入页面不加载js文件的解决方法

    head () { return { title: '', meta: [ { hid: 'description', name: 'description', content: '' } ], sc ...

  2. python基础一 day10(1)

    要背的:

  3. readystatechange

    // alternative to DOMContentLoaded document.onreadystatechange = function () { if (document.readySta ...

  4. AR报表控件的常见问题汇总

    1)字符串格式不正确 原因是建立报表时未使用分页报表 导致拖动数据为sum()表达式,sum运算字符串当然会出问题 2)超出索引 顾名思义 数据为空或不匹配 3)图片使用远程图片时记得把属性修改为远程 ...

  5. k8s master init and add node

    目录 一. add google apt-key 二. k8s master init 三. k8s node add to master cluster(use this command when ...

  6. Java产生GUID

    /** * 产生GUID */public static final String generateGUID(){ UUID uuid = UUID.randomUUID(); return uuid ...

  7. SSH整合JAR包详解

    如果要使用连接池,添加JAR : c3p0-0.9.1.2.jar

  8. bootstrap历练实例:标签式的导航菜单

    本章将讲解bootstrap提供的用于定义导航元素的一些选项,它使用相同的标签和基类.nav.Bootsrtap也提供了一个用于共享标记和状态的帮助器类.改变修饰的class,可以在不同的样式间进行切 ...

  9. iOS开源库

    项目告一段落,总结一下最近学习到的优秀的三方库,希望能帮到别人. (一)网络中常用的 1.网络库:AFNetworking 2.图片缓存:SDWebImage 3.网络监测  Reachability ...

  10. UVa-10474-大理石在哪

    lower_bound()的作用是查找"大于或等于x的第一个位置",但是返回的是地址,所以减去数组的首地址就是偏移量了,也就是整型数字. #include <iostream ...