Error creating bean with name configurationPropertiesBeans defined in class path resource
Describe the bug Show
And this is springdoc config:
When the app starts, there is no error.
Since I'm not sure there is no error on my test code, so I create sample test code like:
but, error still..... :( To Reproduce
Home / Q&A / Migrate spring boot app from 2.4.4 to 2.6.6 we are getting denodo bean creation issue! You can translate the question and the replies: Tag too long 1 AnswerHi, I was able to successfully run the Spring Application by declaring a similar Bean class. In that case, I would make sure that the Denodo JDBC driver is available in the build Path and all the required dependencies are available in the POM.xml. Furthermore, I would check if the there are any differences in the code when using Spring 2.4.4 and Spring 2.6.6. Also, I would first try to only estalibish connection to the source (denodo) to check if the connection itself is established or if the issue is with establishing the connection itself. Furthermore, I would also check in the release notes of the Spring version if there are any changes made in the Spring boot 2.6.6 that is different from the 2.4.4 in the way the source initialisation is done. For any additonal setting/ properties that has to be added to the code. Hope this help! Denodo Team
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. 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.: 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 DependencySome 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 2. Due to Missing DependencySometimes 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 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.propertiesSpring 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 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. 4. Exclude DataSourceAutoConfigurationSometimes 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
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. Why do we get bean creation exception?By far, the most common cause of the BeanCreationException is Spring trying to inject a bean that doesn't exist in the context. To diagnose this type of issue, we'll first make sure the bean is declared: either in an XML configuration file using the
Can not create bean Spring?There could be numerous reasons why Spring could not able to create a bean with name X, but clue always lies on the detailed stack trace. This error always has some underlying cause e.g. a ClassNotFoundException or a NoClassDefFoundError, which potentially signal a missing JAR file in the classpath.
What is the latest spring boot version?What is the latest Spring Boot version? The current stable version, as of July 2022, is Spring Boot 2.7.
|