Tag: transactionmanager

带有2个数据库配置的Spring Boot – 使用第二个配置延迟加载不起作用

我有Spring Boot项目,有2个数据库配置。 主数据库配置: @Configuration @EnableTransactionManagement @EnableJpaRepositories(transactionManagerRef = “primaryTransactionManager”, entityManagerFactoryRef = “primaryEntityManagerFactory”, basePackages = { “com.example.repository.primary” }) public class PrimaryDbConfig { @Primary @Bean(name = “primaryDataSource”) @ConfigurationProperties(prefix = “spring.primary.datasource”) public DataSource dataSource() { return DataSourceBuilder.create().build(); } @Primary @Bean(name = “primaryEntityManagerFactory”) public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder, @Qualifier(“primaryDataSource”) DataSource dataSource) { return builder.dataSource(dataSource).packages(“com.example.domain.primary”).persistenceUnit(“primary-persistence-unit”).build(); } @Primary @Bean(name = “primaryTransactionManager”) public PlatformTransactionManager […]

为什么即使在Spring服务类的第二种方法中传播= Propagation.REQUIRES_NEW时,事务也会回滚?

基本设置现在都很好,我开始尝试交易。 Struts + Spring + Hibernate注释事务管理器。 这是Action中的示例代码,将调用服务类: userService.addUser(); 这是服务类中的addUser()方法: @Transactional(value=”deu” ) public void addUser() { userDao.addUser(); this.addUser2(); } 首先,我在userDao中调用了addUser,它将插入一个用户。 其次,我在此服务类的另一个方法中调用了addUser2 。 @Transactional(value=”deu” , propagation=Propagation.REQUIRES_NEW ) public void addUser2() { //should be a new transaction and will not affect the previous one. //this one will fail but should not affect the previous one. userDao.addUserFail(); } 由于无效PK,这一次将失败。 […]

Spring JDBC事务管理器

我尝试在Spring中使用JDBC编写事务管理器。 我的app-servlet.xml 我的UserDAOImpl.java public class UserDAOImpl implements UserDAO { //transaction manager private DataSourceTransactionManager transactionManager; private JdbcTemplate jdbcTemplate; public UserDAOImpl() { super(); DataSource dataSource = transactionManager.getDataSource(); jdbcTemplate = new JdbcTemplate(dataSource); } public void setTransactionManager(DataSourceTransactionManager transactionManager) { this.transactionManager = transactionManager; } …. } 即使我的app-servlet中有transactionManager Bean, UserDAOImpl也不会被实例化,因为transactionManager为null 。 可能我会错过一些观点,但无法找出问题所在。

什么是优秀的开源Java SE JTA TransactionManager实现?

基本上,它在锡上说的是什么; 我需要一个可在Java SE应用程序中使用的JTA实现,理想情况是它不会带来太多的框架负担。