spring-boot - 微服务、模块和错误编译:注入点有如下注解:
问题描述
我花了一天的时间试图理解,但我无法理解我的问题。
我有 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吗?
感谢您的关注和帮助
解决方案
我查看了您的存储库,发现缺少一些东西
在您的 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);
}
}
就这样..
推荐阅读
- android - 加载页面时如何刷新离子控制器
- python - python GTK3图像来自PIL jpg格式
- php - 如何使用 PHP sdk 在 quicbooks 创建检查条目
- android - 为什么 Xamarin 构建压缩很少的 apk?我该如何改进呢?
- android - Android:通知未使用 Firebase 云消息传递给用户
- google-cloud-platform - 在 GCP 中创建自定义角色
- asterisk - 减少使用 goto 时的时间间隔
- php - 在具有多个值的字符串中搜索 Symfony 3
- react-native - 反应导航。在导航器顶部渲染额外的视图
- python - Python:绘制积分函数