英文:
Entity in a library used by other spring boot apps
问题
我有一个Spring Boot 3应用程序。
我需要创建一个库,将被其他两个Spring Boot应用程序使用。
这些Spring Boot应用程序将拥有自己的实体和存储库,但库也将有一些实体和存储库。
是否有可能为Spring Boot应用程序指定另一个实体的来源?
英文:
I have a spring boot 3 application.
I need to create a library who will be used by two other spring boot apps.
Theses spring boot apps will have their own entity, repository but the library will also have some entity and repository.
Is there a possibility to specify another source of entity for a spring boot apps?
答案1
得分: 1
假设您的库具有基本包 "package.b",而这些应用程序将具有不同的基本包(例如 "package.a"),配置将如下所示:
package package.a;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@SpringBootApplication
@EntityScan(basePackages = {"package.a.model.entity", "package.b.model.entity"})
@EnableJpaRepositories(basePackages = {"package.a.repo", "package.b.repo"})
public class ApplicationThatUsesYourLib {
public static void main(String[] args) {
SpringApplication.run(ApplicationThatUsesYourLib.class, args);
}
}
英文:
Assuming that your library has base package "package.b" and these applications will have different base packages (for example "package.a"), configuration will be something like:
package package.a;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@SpringBootApplication
@EntityScan(basePackages = {"package.a.model.entity", "package.b.model.entity"})
@EnableJpaRepositories(basePackages = {"package.a.repo", "package.b.repo"})
public class ApplicationThatUsesYourLib {
public static void main(String[] args) {
SpringApplication.run(ApplicationThatUsesYourLib.class, args);
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论