`
jeffrey_gao
  • 浏览: 6463 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论

Spring Best Configuration

阅读更多

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>

分享到:
评论

相关推荐

    Learning Spring Application Development

    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

    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.part1

    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.

    Learning Spring Application Development(PACKT,2015)

    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和Mybatis整合英文文档翻译.pdf

    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....

    Spring.MVC.Cookbook.1784396419

    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 ...

    spring-framework-reference-4.1.2

    3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................

    spring dm in action sample chapter6

    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 ...

    Spring.Boot.in.Action.2015.12.pdf

    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使用多线程过程步骤解析

    本文详细介绍了 Spring Boot 中的多线程过程步骤解析,包括配置多线程环境、定义线程池、使用线程池和多线程编程-best Practices。通过学习和掌握这些技术,我们可以编写更加高效、可靠的多线程程序,提高应用程序的...

    spring-framework-reference4.1.4

    3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................

    SpringBoot入门_实战

    在Spring 3.x和4.x时代,Java配置方式已经成为主流,使用Java代码来配置Bean已经成为best practice。 二、Java配置方式 Java配置方式是Spring框架中一种非常重要的配置方式。它允许开发者使用Java代码来配置Bean...

    [Salesforce] Salesforce CRM 权威管理手册 第2版 英文版

    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热加载.md

    ### IDEA 实现 Spring Boot 热加载详解 #### 一、引言 在软件开发过程中,尤其是前后端分离的应用场景下,频繁地修改代码并测试是常态。传统的做法是在每次修改完代码之后都需要手动重启应用服务器,这不仅耗时而且...

    Salesforce.Reporting.and.Dashboards.178439467X

    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 ...

Global site tag (gtag.js) - Google Analytics