In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to configure @Transactional in Spring. Xiaobian thinks it is quite practical, so share it with you for reference. I hope you can gain something after reading this article.
Background:
Older versions of Spring use TransactionProxyFactoryBean to configure Spring transactions (disadvantages own Google, a lot of disadvantages)
Spring 2.x introduces AOP (AOP)
At the beginning, the project also likes to use the spring xml configuration. Later, the project uses the spring3.x version and sees the @Transactional annotation. Personally, I think it is quite convenient and practical. (For whatever reason, I don't know)
code on
classpath:/db.properties classpath:/sqlmap-config.xml classpath*:/sqlmap/*.xml stat 20 1 60000 1 60000 300000 SELECT 'x' true false false true 20 package com.xun.spring3.src.dao;import com.ibatis.sqlmap.client.SqlMapClient;import org.apache.commons.lang.StringUtils;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;import javax.annotation.PostConstruct;import java.lang.reflect.ParameterizedType;import java.lang.reflect.Type;/** * Require the name of each dao to end with Dao * Generic ENTITY -which entity * Generic PRIMARYKEY -type of specific primary key * @Date : 2014/9/7 0007 20:41 * @From : spring3-test * @Author : hebad90@163.com */public class BaseDao extends SqlMapClientDaoSupport { @Autowired private SqlMapClient sqlMapClient; @PostConstruct private void initSuper() { /** * Initialize parent class */ super.setSqlMapClient( sqlMapClient ); } private Class entityClass ; private String ibatisNamespace; protected BaseDao() { Type genType = getClass().getGenericSuperclass(); Type[] params = ((ParameterizedType)genType).getActualTypeArguments(); entityClass = (Class)params[0]; /** * Get namespace XxxDao of current ibatis, i.e. namespace xxx */ this.ibatisNamespace = getIbatisNamespace( getClass() ); System.out.println( "Initialize current environment successfully, ibatisNamespace=["+this.ibatisNamespace+"],entityClass=[" + entityClass + "]" ); } public PRIMARYKEY insert( ENTITY entity ) { return(PRIMARYKEY)super.getSqlMapClientTemplate().insert( this.ibatisNamespace + ".insert", entity ); } public int update( ENTITY entity ) { return super.getSqlMapClientTemplate().update( this.ibatisNamespace + ".update", entity ); } public ENTITY queryById( PRIMARYKEY primarykey ) { return ( ENTITY ) super.getSqlMapClientTemplate().queryForObject( this.ibatisNamespace + ".queryById", primarykey); } public int delete( ENTITY entity ) { return super.getSqlMapClientTemplate().delete( this.ibatisNamespace + ".delete", entity); } ///############################## private String getIbatisNamespace( Class clazz ) { String simpleName = clazz.getSimpleName(); int index = StringUtils.indexOf( simpleName, "Dao" ); return StringUtils.lowerCase( StringUtils.substring( simpleName, 0, index ) ); }}
Where is @Transactional used? Spring recommends that we use this annotation on our business implementation classes because java implementations cannot inherit annotations. Therefore, it is best to annotate the business implementation class so that the business class enables transactions regardless of whether proxy-target-class is true or false.
How to use @Transactional parameters?
About "Spring @Transactional how to configure" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.