When I tried to make a web application using SpringBoot for easy operation verification, it failed at build time. I got the following error.
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).
It seems that the data source setting has failed?
Apparently, it was because I mentioned MyBatis, which I thought I would use later. After deleting the definition of MyBatis from pom.xml, it started normally, but there seems to be other solutions as below.
Add annotations to the [project name Application.java] file.
sample.java
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
@SpringBootApplication
public class MyAppSampleAppApplication {
public static void main(String[] args) {
SpringApplication.run(MyAppSampleApplication.class, args);
}
}
application.properties
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.datasource.driverClassName=org.postgresql.Driver
While researching, I found a description when I want to use multiple databases, so make a note. [How to specify two data sources](https://www.it-swarm.dev/ja/java/spring-boot%E3%81%AF2%E3%81%A4%E3%81%AE%E3 % 83% 87% E3% 83% BC% E3% 82% BF% E3% 82% BD% E3% 83% BC% E3% 82% B9% E3% 82% 92% E8% A8% AD% E5% AE % 9A% E3% 81% 97% E3% 81% A6% E4% BD% BF% E7% 94% A8% E3% 81% 99% E3% 82% 8B / 1053464638 /)
Recommended Posts