我正在尝试在我的应用程序中配置 Spring boot 和 JPA。在搜索互联网后,我配置了我的应用程序,如下所示(仅添加相关代码部分):
pom.xml:
<!-- JPA Starter -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${version.spring.boot}</version>
</dependency>
<!-- MySQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${version.mysql.driver}</version>
</dependency>
application.properties:
spring.datasource.url=jdbc:mysql://localhost/test
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
应用程序配置Java类:
@StatelessBusinessService
@SpringBootApplication(
scanBasePackages = { "com.org.ist.module.service" }
)
@EnableScheduling
public class MyServiceApplication extends SpringBootServletInitializer {
public static void main(final String... args) {
final SpringApplication app = new SpringApplication(MyServiceApplication.class);
app.run(args);
}
@Override
protected SpringApplicationBuilder configure(final SpringApplicationBuilder builder) {
return builder.sources(MyServiceApplication.class);
}
下面是我从终端执行 mvn spring-boot:run
时收到的错误:
***************************
APPLICATION FAILED TO START
***************************
Description:
Cannot determine embedded database driver class for database type NONE
Action:
If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
也许我错过了一些简单的配置?
最佳答案
请尝试在 Spring Boot 应用程序类中添加以下注释,以排除数据源的自动配置。
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
关于java - Spring boot JPA + MySQL 抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45406720/