Spring-引导和多个数据库连接:自动装配服务不工作

Spring-boot & multiple database connections: autowire service does not work

我正在编写一个 Spring-boot 应用程序,它至少需要连接到 2 个数据库。 我每个数据库有 1 个项目来定义它们的域,每个数据库有 1 个项目来定义它们的服务,还有 1 个 Vaadin 项目用于 UI.

 - a business domain entity sample
    @Entity
    @Table(name="T_PARAMETER")
    public class Parameter extends BaseIdEntity implements Serializable {

    @Column(name="par_cls")
    @NotNull
    private String parameterClass;

    @Column(name="par_cd")
    @NotNull
    private String parameterCode;

    @Column(name="par_lan")
    @NotNull
    private String language;

    @Column(name="par_sht_val")
    @NotNull
    private String parameterValueShort;

    @Column(name="par_lng_val")
    @NotNull
    private String parameterValueLong;

 - a authentication domain entity sample

    @Entity
    @Table(name="t_user", schema="authenticate")
    public class User extends BaseIdEntity implements Serializable {

    @Id
    @Column(name="user_cd")
    private String userCode;

    @Column(name="pwd")
    @NotNull
    private String password;

    @Column(name="new_pwd_req")
    @NotNull
    private boolean passwordRequired;

    @Column(name="acc_lck")
    @NotNull
    private boolean accountLocked;

There are repositories onto these 2 entities beans, they just extends the JpaRepository as hereunder:

public interface ParameterRepository extends JpaRepository<Parameter,Integer>{}
2017-12-01 14:20:07.151 ERROR o.s.b.SpringApplication Application startup failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'parameterControllerImpl': Unsatisfied

dependency expressed through field 'serviceParameter'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'serviceParameterImpl': Unsatisfied dependency expressed through field 'parameterRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'parameterRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class org.associative.domain.associativity.Parameter

我已经花了很多时间来解决多个数据库连接,因为我认为这个问题来自定义问题,但我现在不确定。 那么,为了解决这个问题,我应该注意什么。

非常感谢。

堆栈跟踪的最后一行是一个线索:Not a managed type: class org.associative.domain.associativity.Parameter。 Hibernate 不知道您的 Parameter 实体。

LocalContainerEntityManagerFactoryBean 中,您将要扫描的包设置为 org.associative.domain.authenticate。您的参数实体不在此包下。

这应该可以解决问题:

.packages("org.associative.domain.authenticate", "org.associative.domain.associativity")