background
- Use Spring Cloud to build micro-service registration and discovery services being given (Eureka) project started, the following error
*************************** 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 class Action: 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).
The reason given
- The Internet to find a solution, this error will generally be several reasons below
- One reason: Spring Boot configuration, DataSourceAutoConfiguration will automatically load the data source
- This class will be loaded by default when Spring boot org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration start, DataSourceAutoConfiguration class uses the annotation to the spring @Configuration injected dataSource bean. If you can not find the data source configuration file information in the project, the project will error on startup
- Two reasons: no added application.properties/ or application.yml file database configuration information
- Spring Boot classpath will automatically load the data source information in the configuration file, if the data corresponding to the source information is not found, it will error
- Because I built a service registration and discovery (Eureka) project, the project does not require a data source configuration, it is being given a reason: Spring Boot configuration DataSourceAutoConfiguration automatically load the data sources, data source information but can not find cause of
- One reason: Spring Boot configuration, DataSourceAutoConfiguration will automatically load the data source
Solution
- In Spring Boot startup class annotate @SpringBootApplication (DataSourceAutoConfiguration.class the exclude = {}) , represents the start does not require the data source to automatically load the item
@EnableEurekaServer @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}) public class EurekaApplication { public static void main(String[] args) { SpringApplication.run(EurekaApplication.class, args); } }
- Next