You might need this instant guide.
Transactions with Manager and Advice
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
Transactions with Pointcuts
<aop:config>
<aop:pointcut id="projectServiceOperation" expression="execution(* <package>.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="projectServiceOperation" />
</aop:config>
Hibernate Session Factory
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="mappingResources">
<list>
<value><classpath></value>
</list>
</property>
<property name="mappingDirectoryLocations">
<list>
<value>classpath:hbm</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">false</prop>
</props>
</property>
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="eventListeners">
<map>
<entry key="merge">
<bean class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener" />
</entry>
</map>
</property>
</bean>
Hibernate DAO and Service
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="(dao)" class="(daoClass)">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="(service)" class="(serviceClass)">
<property name="hibernateTemplate" ref="hibernateTemplate" />
</bean>
Best Practice
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="NOT_SUPPORTED" read-only="true" />
</tx:attributes>
</tx:advice>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key="hibernate.connection.autocommit">false</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
<property name="mappingDirectoryLocations">
<list>
<value>classpath:hbm</value>
</list>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="entityInterceptor">
<ref local="hibernateInterceptor" />
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/foo</value>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
<property name="nestedTransactionAllowed">
<value>true</value>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
<property name="cacheQueries">
<value>true</value>
</property>
</bean>
<TBC>
分享到:
相关推荐
you will learn best practices through real-world projects and follow a simple, practical approach to developing high performance and enterprise-grade Java applications with Spring. Starting with the...
Spring Recipes: A Problem-Solution Approach, Second Edition continues upon the bestselling success of the previous edition but focuses on the latest Spring 3 features for building enterprise Java ...
Spring in Action, 5th Edition is the fully updated revision of Manning’s bestselling... You’ll also find the latest Spring best practices, including Spring Boot for application setup and configuration.
you will learn best practices through real-world projects and follow a simple, practical approach to developing high performance and enterprise-grade Java applications with Spring. Starting with the...
By translating MyBatis-specific exceptions to Spring's DataAccessException hierarchy, MyBatis-Spring ensures that your application's error handling remains consistent with Spring's best practices....
Fast-paced, practical guide to learn how to set up Spring MVC to produce REST resources and templates as required by the latest front-end best practices Who This Book Is For If you are an experienced ...
3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................
They explore the process of converting existing Java artifacts into OSGi bundles and discuss best practices for designing enterprise applications that leverage OSGi's dynamic capabilities. The ...
8.1 Overriding Spring Boot auto-configuration 50 Securing the application 50. Creating a custom security configuration 51. Taking another peek under the covers of auto-configuration55 8.2 ...
本文详细介绍了 Spring Boot 中的多线程过程步骤解析,包括配置多线程环境、定义线程池、使用线程池和多线程编程-best Practices。通过学习和掌握这些技术,我们可以编写更加高效、可靠的多线程程序,提高应用程序的...
3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................
在Spring 3.x和4.x时代,Java配置方式已经成为主流,使用Java代码来配置Bean已经成为best practice。 二、Java配置方式 Java配置方式是Spring框架中一种非常重要的配置方式。它允许开发者使用Java代码来配置Bean...
13 this book covers best practice administration principles real world experience and critical design considerations for setting up and customizing Salesforce CRM Analyze data within Salesforce by ...
### IDEA 实现 Spring Boot 热加载详解 #### 一、引言 在软件开发过程中,尤其是前后端分离的应用场景下,频繁地修改代码并测试是常态。传统的做法是在每次修改完代码之后都需要手动重启应用服务器,这不仅耗时而且...
Take advantage of creating reports and dashboards in the Salesforce mobile app, updated with Spring '15 release A concise and informative guide to solve all your reporting woes Who This Book Is For ...