繁体   English   中英

Spring Boot JPA + MySQL引发错误

[英]Spring boot JPA + MySQL throws error

我正在尝试在应用程序中配置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

Application configuration Java class:

@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})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM