New Spring boot startup error Failed to auto-configure a DataSource

Learn springboot today and use idea to create projects. Mysq was added when selecting the component, and an error was reported when it was started for the first time. The error message is as follows:

Failed to auto-configure a DataSource: ‘spring.datasource.url’ is not specified and no embedded datasource could be auto-configured.
Reason: Failed to determine a suitable driver class
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).

After multi-party verification, you need to add exclude in the @EnableAutoConfiguration or @SpringBootApplication of the startup class

= {DataSourceAutoConfiguration.class}, exclude this type of autoconfig. After starting, it can run normally.

This is because the database component is added, so autoconfig will read the data source configuration, and my newly created project has not yet configured the data source, so an exception will occur.

Solution to the problem 2: No need to change the adding statement, pay attention to the correctness of the project file structure

Good text to top follow me

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *