Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Spring boot startup prompt what to do with data source error

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the Spring boot startup prompt data source error how to do, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor with you to understand.

An error indicating that the data source is not configured when starting the Spring Boot project.

08333 [main] DEBUG o.s.b.d.LoggingFailureAnalysisReporter-Application failed to start due to an exceptionorg.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver classat org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName (DataSourceProperties.java:233) at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder (DataSourceProperties.java:174)

Spring will prompt you that the complete message that causes the startup error is:

* * APPLICATION FAILED TO START**Description:Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.Reason: Failed to determine a suitable driver classAction:Consider the following: If you want an embedded database (H2, HSQL or Derby), please put it on the classpath. If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active). Process finished with exit code 1 error analysis

Judging from the startup information above, it is very clear that you have configured the data component of Spring, but you have not configured the corresponding data source.

Because this will cause your startup to fail.

Solution.

There are the following centralized solutions:

Add H2 packet

The easiest solution is to add a H2 database to the dependency, which is also required if you use Spring Batch, because Spring uses H2 as the data source.

Add data source configuration

If you have added a database driver, for example, you have added a database driver for mysql.

Then you need to set the database connection parameters for Mysql.

Spring.datasource.url=jdbc:mysql://localhost:3306/myDbspring.datasource.username=user1spring.datasource.password=passspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver does not load the data source configuration at startup.

You can use not to load the data source configuration at startup.

Can be used on the startup class, add the following comments.

@ SpringBootApplication (exclude= {DataSourceAutoConfiguration.class})

You can also add the following to the startup configuration file to ensure that you do not load the data source configuration class at startup.

Spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAuto thank you for reading this article carefully. I hope the article "Spring boot Startup Tips how to do data Source errors" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and follow the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report