首页 > 解决方案 > 微服务、模块和错误编译:注入点有如下注解:

问题描述

我花了一天的时间试图理解,但我无法理解我的问题。

我有 1 个弹簧模块(https://spring.io/guides/gs/multi-module/)[我在子模块中也有 JPA] 和 2 个微服务(A 和 B)。

在微服务 A 中,我到达 @Autowired CountryRepository(从 JpaRepository 扩展而来),它运行良好,SpringBootApplication (scanBasePackages = "**") 使用,我访问我的数据并且我可以编译。

在微服务 B 上,我做了同样的事情,我设法访问了我的数据,但无法编译:

****************************
FAILED TO START APPLICATION
****************************

Description:

Field countryRepository in * required a bean named 'entityManagerFactory' that could not be found.

The injection point has the following annotations:
        - @ org.springframework.beans.factory.annotation.Autowired (required = true)


Action:

Consider defining a bean named 'entityManagerFactory' in your configuration.

我无法理解或寻找错误,如何解锁自己,我一次又一次地搜索,但我无法理解为什么微服务 B 不想编译。

我使用 POM 父级,并且小心地按以下顺序排列:

<modules>
<module>sub module </module>
<module> microservice A </module>
<module> microservice B </module>
</modules>

所以我破解,没有太多了解,有时我有不同的消息,但总是编译失败

具体来说,可以使用微服务A和B中子模块的Repositories吗?

感谢您的关注和帮助

标签: spring-bootspring-modules

解决方案


我查看了您的存储库,发现缺少一些东西

在您的 CountryRepository.java 类中

@Repository 
public interface CountryRepository extends JpaRepository<Country, Long> {
}

缺少@Repository 注释,您需要添加它

然后在您的主要服务 A 和服务 B 中,您必须添加如下

@SpringBootApplication
@EnableJpaRepository("com.submodule.commun.modelandjpa.Repository")
public class ParentApplication {

public static void main(String[] args) {
    SpringApplication.run(ParentApplication.class, args);
}

}

就这样..


推荐阅读