Error creating bean with name transactionManager defined in class path resource

标签: 异常

Show

错误

Error creating bean with name 'transactionManager' defined in class path resource [spring-dao.xml]:
Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'dataSource' is required

原因:配合事物的时候,没有注入值

错误代码

Error creating bean with name transactionManager defined in class path resource

 解决办法:给他把值注入

正确代码

Error creating bean with name transactionManager defined in class path resource

 ..


智能推荐

Meavn 搭建项目遇到Error creating bean with name 'sessionFactory' defined in class path resource

Error creating bean with name 'sessionFactory' defined in class path resource 。nested exception is java.io.FileNotFoundException: class path resource [com/test/domain/Department.bhm.xml] 原错误大意为 : Spri...

Error creating bean with name 'entityManagerFactory' defined in class path resource

错误详细信息: 参考解决问题链接: Error creating bean with name ‘entityManagerFactory’ defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: ...

使用SpringMVC报错 Error creating bean with name 'conversionService' defined in class path resource [springmvc.xml]

使用SpringMVC报错 Error creating bean with name 'conversionService' defined in class path resource [springmvc.xml] Could not instantiate bean class [org.springframework.core.convert.support.ConversionServ...

spring创建错误:Error creating bean with name 'hello' defined in class path resource [application.xml]

spring创建错误:Error creating bean with name 'hello' defined in class path resource [application.xml] 错误提示:   不要说了,在application.xml的时候忘记给实现类创建get()来获取对象了,所以直接GG。   解决方法:只需要在测试类中加上get和对应的set方法就...

Error creating bean with name transactionManager defined in class path resource

数据库重构工具 LiquiBase被锁,报错Error creating bean with name 'liquibase' defined in class path resource ....

问题:https://blog.csdn.net/qq_35503293/article/details/10415469         解决:https://blog.51cto.com/moerjinrong/2326085 mysql查看被锁住的表 查询是否锁表 查看所有进程 MySQL: mariabd: 查询到相对应的进程===然后 kill i...

猜你喜欢

SpringBoot项目测试类报错: Error creating bean with name 'serverEndpointExporter' defined in class path resource ...

异常 : 解决方法: 引入: 在SpringBootTest注解中添加webEnvironment配置: 参考博客: https://www.jianshu.com/p/bac3aa8cdc02...

【报错】org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webSocketHandlerMapping' defined in class path resource

环境:maven+eclipse+jdk1.8 [tomcat使用的是maven自带的插件,实质原因就是出在tomcat版本问题] 背景:在进行SSM集成WebSocket的时候,项目启动报org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webSocketHandlerM...

吴裕雄--天生自然--Spring Boot--解决 Error creating bean with name 'entityManagerFactory' defined in class path resource

 ...

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [bean.xml]: Invocation of init method failed; nested exception is

在复制xml文件进行修改的时候,我经常将不小心对原文件进行修改,而导致创建bean出错。报错如下所示:  ...

Error creating bean with name transactionManager defined in class path resource

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stu' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is

 ...

Hello guys, If you are using Spring Boot and getting errors like "Cannot determine embedded database driver class for database type NONE" or "Error creating a bean with name 'dataSource' defined in class path resource ataSourceAutoConfiguration" then you have come to the right place. In this article, we'll examine different scenarios on which this Spring Boot error comes and what you can do to solve them. The general reason for this error is Spring Boot's auto-configuration, which is trying to automatically configure a DataSource for you but doesn't have enough information. It is automatically trying to create an instance of DataSourceAutoConfiguration bean and it's failing.

Like other Spring frameworks errors, the stack trace looks quite messy, something which they could have improved with Spring Boot, but the gest is here are these two errors I mentioned above.

Let's see the stacktrace looks in general:

org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource()] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.:
[INFO] org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.

Btw, these errors can be intimidating if you are completely new to Spring framework. In that case, I suggest you go through a comprehensive Spring Boot course like the Learn Spring Boot by Dan Vega on Udemy.   Now, let's see some common cause of this error and what you can do to solve this problem.

1. Spring Boot Error due to Starter Dependency

Some of my friends and readers got this error even if they don't need a Database. The main reason they were getting this error was because of starter dependency like some of they have included spring-boot-starter-data-jpa which then included hibernate-entitymanager.jar and they didn't have additional things need to set that up.

Sometimes including incorrect Starter POM can also solve this problem like adding spring-boot-starter-jdbc instead of spring-boot-starter-data-jpa dependency.

If you know, Spring Boot auto-configuration is triggered by JAR dependencies present in the classpath and if it pulls something which you don't need then this type of error can come.

That's why a good knowledge of Spring fundamentals are needed to use Spring boot correctly. If you are new into the Spring framework, I suggest you go through Learn Spring: The Certification Class by Eugen Paraschiv of Baeldung to learn Spring 5 and Spring Boot 2 from scratch, in a guided, code-focused way

Error creating bean with name transactionManager defined in class path resource

2. Due to Missing Dependency

Sometimes you do need a database but you forgot to include the driver JAR file into the classpath, which can also cause this error. For example, you have specified the following properties in the application.properties, spring boots configuration file but didn't include the corresponding MySQL JDBC driver into the classpath

spring.datasource.url = jdbc:mysql://localhost/test
spring.datasource.driver-class-name= com.mysql.jdbc.Driver

In order to solve this error, either you need to include the correct Starter POM dependency or manually add the MySQL JDBC JAR file into the classpath. If you are interested, you can see this tutorial to learn more about how to connect a Java application to a database using a MySQL database in this tutorial.

3. Due to Missing Configuration in Application.properties

Spring Boot is good at configuring in-memory Databases like H2, HSQLDB, Derby, etc and it can configure them by just adding their JAR files into the classpath but for others, you need to give Spring Boot additional details like URL, DriverClass name, etc.

You can do that by adding some properties to application.properties file with the spring.datasource prefix, as shown in following example:

spring.datasource.url = jdbc:mysql://localhost/abc
spring.datasource.name=testme
spring.datasource.username=xxxx
spring.datasource.password=xxxx
spring.datasource.driver-class-name= com.mysql.jdbc.Driver spring.jpa.database=mysql
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect

This will provide the Spring Boot auto-configuration component to configure the database for you. If you want to learn more about how auto-configuration works in Spring Boot, I suggest you go through a comprehensive Spring boot course like Spring Boot: Efficient Development, Configuration, and Deployment course on Pluralsight, which will also teach you the details behind @EnableAutoConfiguration by writing your own auto configurations.

Error creating bean with name transactionManager defined in class path resource

4. Exclude DataSourceAutoConfiguration

Sometimes excluding DataSourceAutoConfigution can also solve this problem, especially if you don't need Database. This will prevent Spring Boot from automatically configuration database and there won't be any error. You can disable auto-configuration for certain classes by using the exclude Attribute of @EnableAutoConfiguration annotation of Spring Boot as shown below:

@Configuration @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) public class SpringBootDemo {   public static void main(String[] args) { SpringApplication.runSpringBootDemo.class, args); }   }

You can even exclude more than one classes using exclude attribute with @EnableAutoConfiguration as shown below:

@Configuration @EnableAutoConfiguration( exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class}) public class SpringBootDemo {   public static void main(String[] args) { SpringApplication.runSpringBootDemo.class, args); }   }

That's all about how to solve "Cannot determine embedded database driver class for database type NONE" or "Error creating a bean with name 'dataSource' defined in class path resource DataSourceAutoConfiguration" problem. In most of the cases, it is because of auto-configuration doesn't have enough details require to configure Database but sometimes it's also the accidental trigger of database auto-configuration which can be disabled using exclude attribute of @EnableAutoConfiguration annotation.

Btw, if you want to learn Spring Boot in depth, here are some useful resources for your learning:

Other Java and Spring Boot articles you may like

  • 5 Spring Boot Features Every Java Developer Should Know (features)
  • Top 5 Free Courses to learn Spring and Spring Boot  (courses)
  • 15 Spring Boot Interview Questions for Java developers (questions)
  • 5 Course to Master Spring Boot online (courses)
  • 10 Things Java Developer should learn (goals)
  • 10 Tools Java Developers use in their day-to-day life (tools)
  • 10 Tips to become a better Java developer  (tips)
  • 3 Best Practices Java Programmers can learn from Spring (best practices)
  • Top 5 Spring Boot Annotations Java Developers should know (annotations)
  • 5 books to learn Spring Boot and Spring Cloud (books)
  • 5 courses to learn Spring Boot in depth ( courses)
  • 21 Skills Java Developers Can Learn to Enhance heir profile (skills)

Thanks for reading this article so far. If you like my explanation and solution of this Spring Boot error then please share with your friends and colleagues. If you have any questions or feedback then please drop a note.

P. S. - If you are interested in learning Spring Boot but looking for a free course to start with then I suggest you check the Free Introducing Spring Boot course on Udemy to kick start your journey into the beautiful world of Spring.