当我试图使用spring代码创建关系时,我得到了事务管理器错误。我正在我的项目中使用Mysql和Neo4j数据库。我尝试了不同的解决方法,但都解决不了。
noSuchBeanDefinitionException:没有名为“Transaction Manager”的bean可用:没有为限定符“Transaction Manager”找到匹配的PlatformTransactionManager bean-既没有限定符匹配,也没有bean名称匹配!
pom.xml文件如下所示
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.10.RELEASE</version>
</dependency>
<!-- For Neo4J Graph Database -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.9-rc</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>1.5.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>
</properties>
</project>
@SpringBootApplication
@EnableTransactionManagement
@EntityScan("projectone.entities")
public class Application {
public static void main(String[] args) {
//For Starting application
ApplicationContext applicationContext=SpringApplication.run(Application.class, args);
}
}
@Configuration
@EnableJpaRepositories(basePackages = {"projectone.mysql"},
entityManagerFactoryRef = "dbEntityManager",
transactionManagerRef = "dbTransactionManager")
@EnableTransactionManagement
public class DatabaseConfiguration {
@Autowired
private Environment env;
@Bean
@Primary
public LocalContainerEntityManagerFactoryBean dbEntityManager() {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dbDatasource());
em.setPackagesToScan(new String[]{"projectone.mysql"});
em.setPersistenceUnitName("dbEntityManager");
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
HashMap<String, Object> properties = new HashMap<>();
properties.put("hibernate.dialect",env.getProperty("hibernate.dialect"));
properties.put("hibernate.show-sql",env.getProperty("jdbc.show-sql"));
em.setJpaPropertyMap(properties);
return em;
}
@Primary
@Bean
public DataSource dbDatasource() {
DriverManagerDataSource dataSource
= new DriverManagerDataSource();
dataSource.setDriverClassName(
env.getProperty("spring.datasource.driverClassName"));
dataSource.setUrl(env.getProperty("spring.datasource.url"));
dataSource.setUsername(env.getProperty("spring.datasource.username"));
dataSource.setPassword(env.getProperty("spring.datasource.password"));
return dataSource;
}
@Primary
@Bean
public PlatformTransactionManager dbTransactionManager() {
JpaTransactionManager transactionManager
= new JpaTransactionManager();
transactionManager.setEntityManagerFactory(
dbEntityManager().getObject());
return transactionManager;
}
}
如果我只使用@SpringBootApplication注释,那么我将得到以下异常:它正在抛出
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mappingController': Unsatisfied dependency expressed through field 'branchService';
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'branchServiceImplementaion': Unsatisfied dependency expressed through field 'branchRepository';
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'branchRepository': Unsatisfied dependency expressed through method 'setSession' parameter 0;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.data.neo4j.transaction.SharedSessionCreator#0': Cannot resolve reference to bean 'sessionFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.neo4j.ogm.session.SessionFactory]: Factory method 'sessionFactory' threw exception; nested exception is NullPointerException
终于发现了错误:
@Bean
public PlatformTransactionManager dbTransactionManager() {
JpaTransactionManager transactionManager
= new JpaTransactionManager();
transactionManager.setEntityManagerFactory(
dbEntityManager().getObject());
return transactionManager;
}
本节错误导致了上述问题。将@bean更改为@bean(Name=“TransactionManager”)就解决了这个问题。
请求处理失败;嵌套的异常是org。springframework。豆。工厂NoSuchBeanDefinitionException:没有名为“transactionManager”的bean可用:没有为限定符“transactionManager”找到匹配的transactionManager bean-既没有限定符匹配,也没有bean名称匹配! 客户请求。JAVA 客户控制器 顾客道 spri
问题内容: 我已经用实体管理器配置了两个持久性单元,如下所示: 然后,我将事务管理器配置为 我最初只有一个配置,它被称为“ transactionManager”。Addint一个附加的持久性单元似乎会生成错误。我不明白的一件事,如果我配置了两个持久性单元(每个持久性单元用于一个单独的数据库),是否还需要为每个数据源配置一个单独的实体管理器和一个事务管理器? 我得到的错误如下所示:(我搜索了所有文
当我尝试在junit测试类中加载配置文件时,在注入数据源时出现以下错误: 组织。springframework。豆。工厂NoSuchBeanDefinitionException:在组织中未定义名为“transactionManager”的bean。springframework。豆。工厂支持DefaultListableBeanFactory。位于org的getBeanDefinition(De
我创建了一个Spring Boot应用程序,并使用我想要执行的方法创建了一个类。将项目部署为war文件时,我从stacktrac中获取错误。我想从类TennisExecitor中运行该方法。 没有名为'entityManagerFactory'的bean可用 创建名为'(内部bean)#366583f9'的bean时出错:设置构造函数参数时无法解析对bean'entityManagerFactor
我在构建时遇到了这个错误。我在这里参考了其他的答案,但没有一个对我有效。 应用程序.属性 存储库: 实体: 和pom.xml 和主类(spring boot应用程序) 我从.m2目录中删除了所有文件夹。再次运行mvn clean install。得到了同样的错误。服务类自动连接存储库。控制器使用@RestController注释。 而这正是确切的原因: 原因:org.springframework
我正在尝试开发一个新的批与Spring批和jpa。当我尝试启动它时,我收到错误"嵌套异常是org.springframework.beans.factory.NoSuchBean定义异常:没有名为'entityManagerFactory'可用的bean" 我的pom.xml 我的数据源配置类: 我的存储库类: 我的实体类: pplication.properties: 如果我尝试启动应用程序,我