java - Spring boot JPA + MySQL 抛出错误

标签 java mysql maven jpa spring-boot

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

相关文章:

java - STS Spring 与 Roo 和 Maven - 太慢了?

java - Spring Boot 找不到 IntelliJ

java - com.solacesystems.jms.ConfigurationException : Invalid scheme "null" in host "null://x.x.x.x:x"

java - 适应 map 缩减框架有哪些挑战性问题?

php - 即使安装了Laravel-homestead也找不到Mysql

mysql - 查找 MySQL/MariaDB 中项目的排名和总数

javax.管理.InstanceNotFoundException : Catalina:type=Server occurs when I run debug using Tomcat7 in IntelliJ IDEA

java - 在背景图像上添加 JPanel/Containers/Images/JButton/等等?

php - 日期匹配循环

java - 适用于 Java 7 的简单代码指标独立 Maven 插件