簡體   English   中英

Java:依賴項目中的spring-boot-starter-data-jpa依賴

[英]Java : spring-boot-starter-data-jpa dependency in a dependent project

我已經用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文件為空。

問題是為什么我會收到此錯誤。

您應該使用Spring Boot配置一個帶有依賴模塊的交付應用程序

你可以有例如

myproject-parent
       |
    myproject-api
    myproject-ui

如果您的交付項目(主要戰爭/罐子)是myproject-api,則必須在myproject-api@SpringBootApplication范圍內配置application.properties和@Configuration

您不能有兩個@SpringBootApplication范圍

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM