Entity in a library used by other spring boot apps

huangapple go评论89阅读模式
英文:

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);
	}

}

huangapple
  • 本文由 发表于 2023年3月12日 09:42:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75710632.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定