简体   繁体   English

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

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

I have build two projects using Java 我已经用Java建立了两个项目

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

myproject-db uses spring-boot-starter-data-jpa as a dependency and I am able to build and install it all fine. myproject-db使用spring-boot-starter-data-jpa作为依赖项,我能够很好地构建和安装它。

myproject-api - is a spring boot project and it uses myproject-db as a dependency. myproject-api-是一个春季启动项目,它使用myproject-db作为依赖项。 When I run my myproject-api project it gives me error 当我运行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

I have defined my dataSource url application.properties file in myproject-db like below 我已经在myproject-db中定义了dataSource url application.properties文件,如下所示

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

application.properties file of myproject-api is empty. myproject-api的application.properties文件为空。

Question is why am I getting this error. 问题是为什么我会收到此错误。

You should have one delivery application configured with Spring Boot with dependent modules 您应该使用Spring Boot配置一个带有依赖模块的交付应用程序

You can have for example 你可以有例如

myproject-parent
       |
    myproject-api
    myproject-ui

If your delivery project (main war/jar) is myproject-api then application.properties and @Configuration must be configured in myproject-api and in @SpringBootApplication scope 如果您的交付项目(主要战争/罐子)是myproject-api,则必须在myproject-api@SpringBootApplication范围内配置application.properties和@Configuration

You cannot have two @SpringBootApplication scopes 您不能有两个@SpringBootApplication范围

暂无
暂无

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

相关问题 spring-boot-starter-data-jpa依赖错误 - spring-boot-starter-data-jpa dependency error 将“spring-boot-starter-data-jpa”依赖项添加到Spring项目时出错 - Error when adding “spring-boot-starter-data-jpa” dependency to Spring project 未找到依赖项 'org.springframework.boot:spring-boot-starter-data-jpa:2.5.3' - Dependency 'org.springframework.boot:spring-boot-starter-data-jpa:2.5.3' not found Spring 引导不添加 spring-boot-starter-data-jpa - Spring boot not adding spring-boot-starter-data-jpa 有什么办法可以不在 spring-boot-starter-data-jpa 依赖中使用 exclude 并保持相同的存储吗? - Is there any way to not to use exclude in the spring-boot-starter-data-jpa dependency and maintain the same storage? 有关Spring-boot-starter-data-jpa的问题 - A question about the Spring-boot-starter-data-jpa spring-boot-starter-data-jpa:自动重新连接 - spring-boot-starter-data-jpa : Auto Reconnect 旧版 spring 引导项目在 pom.xml 和事务中带有 spring-boot-starter-data-jpa 和 spring-tx? - Legacy spring boot project with spring-boot-starter-data-jpa and spring-tx in pom.xml and transactions? H2 数据库是用 spring-boot-starter-data-jpa 创建的,但不是用 spring-boot-starter-data-jdbc 创建的 - H2 Database created with spring-boot-starter-data-jpa but not with spring-boot-starter-data-jdbc spring-data-jpa和spring-boot-starter-data-jpa之间的区别 - Difference between spring-data-jpa and spring-boot-starter-data-jpa
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM