【问题标题】:Spring Boot project using a spring data jpa project to retrieve usersSpring Boot项目使用spring data jpa项目检索用户
【发布时间】:2017-11-07 07:09:12
【问题描述】:

我有一个 Spring Data JPA 项目来访问我的数据库并检索用户凭据。我将此项目打包为 jar(不是可执行 jar)并将其作为 maven 依赖项包含到另一个 Spring boot 项目中,因为我想重用之前开发的相同实体和存储库。每次我运行我的 Spring Boot 应用程序时,我都会收到此错误:

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).

我开始怀疑我正在做的事情是否可能? PS:我不想将 JPA 项目与控制器和服务项目混在一起

【问题讨论】:

  • 我认为您的类路径中缺少 DB JAR。
  • 我有<dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>9.4.1212.jre7</version> </dependency>
  • 在 Spring Boot 应用程序中?
  • 是的,我两个都有
  • 你添加了'spring.database.driverClassName=org.postgresql.Driver'驱动类名吗?

标签: maven spring-boot spring-security spring-data spring-data-jpa


【解决方案1】:

前段时间我遇到了同样的错误,我修复它添加这个:

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

到引导类,例如:

package com.adapter;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

@SpringBootApplication
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class DBAdapterApplication {
    public static void main(String[] args) {
        SpringApplication.run(DBAdapterApplication.class, args);
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-28
    • 2017-03-19
    • 2016-08-13
    • 2020-07-04
    • 1970-01-01
    • 1970-01-01
    • 2020-01-04
    • 2021-07-08
    相关资源
    最近更新 更多