Java:依赖项目中的spring-boot-starter-data-jpa依赖

时间:2018-10-08 06:31:36

标签: java spring-boot spring-data-jpa

我已经使用Java构建了两个项目

  1. myproject-db-用于数据库交互
  2. myproject-api-用于公开api调用

myproject-db使用spring-boot-starter-data-jpa作为依赖项,我能够很好地构建和安装它。

myproject-api-是一个春季启动项目,它使用myproject-db作为依赖项。当我运行myproject-api项目时,它给我错误

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

我已经在myproject-db中定义了我的dataSource url application.properties文件,如下所示

spring.datasource.url=jdbc:mysql://localhost:3306/somedb?useSSL=false
spring.datasource.username=root
spring.datasource.password=somepass

myproject-api的application.properties文件为空。

问题是为什么我会收到此错误。

1 个答案:

答案 0 :(得分:0)

您应该使用Spring Boot配置一个带有依赖模块的交付应用程序

例如,您可以拥有

myproject-parent
       |
    myproject-api
    myproject-ui

如果您的交付项目(主要战争/罐子)是myproject-api,则必须在@Configurationmyproject-api范围内配置application.properties和@SpringBootApplication

您不能有两个@SpringBootApplication范围

相关问题