我解决了, 正是事务配置问题。
经过琢磨研究,我把事务配置修改成如下解决了:
package com.hl.core.conf;
import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.interceptor.TransactionInterceptor;
import java.util.Properties;
/**
* @author zhangweilin
* @date 2018/11/24 21:05
* @Description: 全局声明式事务(此配置解决事务内修改不可见问题 , 此坑消耗了我整整两天一夜研究琢磨,)
*/
//@Component
@Configuration
public class TxConfig2 {
@Autowired
private PlatformTransactionManager transactionManager;
@Bean(name = "txAdvice")
public TransactionInterceptor getAdvisor() throws Exception {
System.out.println("transactionManager = " + transactionManager);
Properties properties = new Properties();
properties.setProperty("init*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("add*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("insert*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("create*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("persist*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("update*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("modify*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("merge*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("bind*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("del*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("drop*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("remove*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("reset*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("cancel*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("login*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("save*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("update*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("delete*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("*", "PROPAGATION_REQUIRED,-Exception,readOnly");
TransactionInterceptor tsi = new TransactionInterceptor(transactionManager, properties);
return tsi;
}
@Bean
public BeanNameAutoProxyCreator txProxy() {
BeanNameAutoProxyCreator creator = new BeanNameAutoProxyCreator();
creator.setInterceptorNames("txAdvice");
creator.setBeanNames("*Service","*Dao");
creator.setProxyTargetClass(true);
return creator;
}
}
这个坑,踩了我很久,此解决方案,已同步更新到stackoverflow了