`
yuhaibo6646737
  • 浏览: 15950 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

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: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.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:property-placeholder
location="classpath:jdbc.properties" />
<!-- 配置数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="user" value="${user}"></property>
<property name="password" value="${password}"></property>
<property name="driverClass" value="${driverClass}"></property>
<property name="jdbcUrl" value="${jdbcUrl}"></property>

<property name="maxPoolSize" value="5"></property>
<property name="minPoolSize" value="2"></property>
<property name="initialPoolSize" value="2"></property>
<property name="acquireIncrement" value="2"></property>
</bean>
<!-- 配置本地会话工厂bean :整合hibernate资源的核心入口-->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 数据源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- hibernate属性集 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
</props>
</property>
<!-- 映射资源集 -->
<property name="mappingDirectoryLocations">
<value>classpath:cn/itcast/ssh/domain</value>
</property>
</bean>
<!-- 配置基于会话工厂的DAO -->
<bean id="PersonDaoImpl3SessionFactory"
class="cn.itcast.ssh.dao.impl.PersonDaoImpl3SessionFactory">
<property name="sf" ref="sessionFactory"></property>
</bean>
<!-- *****************业务层面上声明式事务管理: 事务管理配置 ***************** -->
<!-- 配置基于会话工厂的hibernate事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 事务实现类对象属性注入 -->
<bean id="personService" class="cn.itcast.ssh.service.impl.PersonServicePojoXml">
<property name="pd" ref="PersonDaoImpl3SessionFactory"></property>
</bean>
<!-- 定义通知: 方法应用策略: 即什么方法上应用什么事务策略 -->
<tx:advice transaction-manager="transactionManager" id="txadvice">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" isolation="DEFAULT"/>
<tx:method name="update*" propagation="REQUIRED" isolation="DEFAULT"/>
<tx:method name="delete*" propagation="REQUIRED" isolation="DEFAULT"/>
<tx:method name="get*" propagation="REQUIRED" isolation="DEFAULT" read-only="true"/>
<tx:method name="load*" propagation="REQUIRED" isolation="DEFAULT" read-only="true"/>
<tx:method name="find*" propagation="REQUIRED" isolation="DEFAULT" read-only="true"/>
<tx:method name="*" propagation="REQUIRED" isolation="DEFAULT"/>
</tx:attributes>
</tx:advice>
<!-- 配置切入点通知组合体 -->
<aop:config><!-- 切入点:  应用通知的地点-->
<aop:pointcut expression="execution(* *..*Service.*(..))" id="txpct"/>
<!-- 切入点上应用的通知 : -->
<aop:advisor advice-ref="txadvice" pointcut-ref="txpct"/>
</aop:config>

</beans>

//*..表示所有包以及所有包下的子包. 用法 *..*Service.*(..)
分享到:
评论

相关推荐

    SSH2完整典型配置实例

    struts2,spring,hibernate整合实例!找了好久,这个是比较完整的!以一book,增加/删除/列表/修改/分页为基础!

    spring2+hibernate3典型配置

    本文主要列举在一个sping2+hibernate3的框架实例中出现的相关配置文件信息以备参考,如何使用请自行研究spring和hibernate文档。

    spring3.0jar包

    ◆容器——Spring包含并管理应用对象的配置和生命周期,在这个意义上它是一种容器,你可以配置你的每个bean如何被创建——基于一个可配置原型(prototype),你的bean可以创建一个单独的实例或者每次需要时都生成一...

    Spring 中文API&开发文档.rar

    ◆容器——Spring包含并管理应用对象的配置和生命周期,在这个意义上它是一种容器,你可以配置你的每个bean如何被创建——基于一个可配置原型(prototype),你的bean可以创建一个单独的实例或者每次需要时都生成一...

    spring-framework-3.1.0.RELEASE.zip

    容器——Spring包含并管理应用对象的配置和生命周期,在这个意义上它是一种容器,你可以配置你的每个bean如何被创建——基于一个可配置原型(prototype),你的bean可以创建一个单独的实例或者每次需要时都生成一个...

    Spring中文帮助文档

    6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ加载时织入(LTW) 6.9. 更多资源 7. Spring AOP APIs 7.1. 简介 7.2. Spring中的切入点API 7.2.1. 概念 7.2.2. 切入点运算 ...

    Spring API

    6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ加载时织入(LTW) 6.9. 更多资源 7. Spring AOP APIs 7.1. 简介 7.2. Spring中的切入点API 7.2.1. 概念 7.2.2. 切入点运算 ...

    Spring.net框架

    通过ConfigHandler的解析,我们最终得到一个ConfigInfo实例,Factory就是根据这个实例中所包含的配置信息,利用反射技术对所需对象生成并组装的。SayHelloFactory的代码如下: using System; using System.IO; using...

    第24次课-1 Spring与Hibernate的整合

    Spring提供了很多IoC特性的支持,方便处理大部分典型的Hibernate整合问题。 如:SessionFactory的注入、HibernateTemplate的简化操作、DAO的支持等。 为了更好地与持久层框架整合,Spring还提供了统一的异常处理体系...

    Spring 3 Reference中文

    4.10.1 @Component和更多典型注解 97 4.10.2 自动检测类和bean 的注册. 97 4.10.3 使用过滤器来自定义扫描 98 4.10.4 使用组件定义bean 的元数据.. 99 4.10.5 命名自动检测组件 100 4.10....

    Spring面试题

    ☆ Spring AOP:通过配置管理特性,Spring AOP 模块直接将面向方面的编程功能集成到了 Spring 框架中。所以,可以很容易地使 Spring 框架管理的任何对象支持 AOP。Spring AOP 模块为基于 Spring 的应用程序中的对象...

    spring3.1中文参考文档

    spring3.1中文参考文档,南磊翻译,现在有4章,目录如下: 第一部分 Spring framework概述.......................................................................................................................

    java web技术开发大全(最全最新)

    和已经出版的同类图书相比,《Java Web开发技术大全:JSP+Servlet+Struts+Hibernate+Spring+Ajax》讲解由浅入深,涵盖更多内容,列举了大量典型实例具有超强的实用性,另外,《Java Web开发技术大全:JSP+Servlet+...

    JAVA上百实例源码以及开源项目源代码

     Java编写的山寨QQ,多人聊天+用户在线,程序分服务端和客户端,典型C/S结构,  当用户发送第一次请求的时候,验证用户登录,创建一个该qq号和服务器端保持通讯连接得线程,启动该通讯线程,通讯完毕,关闭Scoket...

    java web开发技术大全

    和已经出版的同类图书相比,《Java Web开发技术大全:JSP+Servlet+Struts+Hibernate+Spring+Ajax》讲解由浅入深,涵盖更多内容,列举了大量典型实例具有超强的实用性,另外,《Java Web开发技术大全:JSP+Servlet+...

    JAVA上百实例源码以及开源项目

     Java编写的山寨QQ,多人聊天+用户在线,程序分服务端和客户端,典型C/S结构,  当用户发送第一次请求的时候,验证用户登录,创建一个该qq号和服务器端保持通讯连接得线程,启动该通讯线程,通讯完毕,关闭Scoket...

    Java Web开发从初学到精通随书光盘源码

    Web开发中,Strurts+Hibemate+Spring已经成为轻量级开发J2EE的标准配置,但一些Ajax和JSF框架也应用很广泛,这些是目前Java程序员必须掌握的技能。《Java Web开发从初学到精通》的编写顺序从基础到框架,先让读者...

Global site tag (gtag.js) - Google Analytics