根据baeldung here
如果我们使用的是Spring Boot项目,并且在类路径上具有spring-data- *或spring-tx>依赖项,那么将通过> default启用事务管理。”
但是,我有此错误:
org.springframework.messaging.MessageHandlingException:在“ MethodInvokingMessageProcessor”中处理消息期间发生错误[org.springframework.integration.handler.MethodInvokingMessageProcessor@788f2bfc];嵌套的异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有可用的名为“ transactionManager”的bean:找不到与限定符“ transactionManager”匹配的TransactionManager bean-限定符不匹配,bean名称不匹配!
具有以下依赖关系:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-artemis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.indra.icens</groupId>
<artifactId>ic-license</artifactId>
</dependency>
<dependency>
<groupId>javax.jms</groupId>
<artifactId>javax.jms-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-jms</artifactId>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>mq</artifactId>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>mqjms</artifactId>
</dependency>
<dependency>
<groupId>javax.resource</groupId>
<artifactId>connector</artifactId>
</dependency>
<dependency>
<groupId>com.indra.icens.srom</groupId>
<artifactId>ic_int_srom_common</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
</dependency>
</dependencies>
application.properties:
spring.datasource.url=jdbc:postgresql://xxx/yyy
spring.datasource.username=asdasd
spring.datasource.password=werwer
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL95Dialect
spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
spring.jpa.show-sql=false
ServiceConfig.java
@EnableJms
@Configuration
@ImportResource({
"classpath:/META-INF/spring/integration/main-config.xml"
})
@EnableJpaRepositories("com.nbi.conn.repository")
@EntityScan("com.nbi.conn.entities")
public class ServiceConfig {
}
有什么问题吗?我的SpringBoot Config中缺少什么?
在此先感谢您的帮助
最佳答案
您是否尝试像这样在配置中添加一个bean“ transactionManager”
@Bean
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(emf);
return transactionManager;
}