简体   繁体   English

在多模块Spring Boot项目中无法使用@EnableJpaRepositories

[英]Unable to use @EnableJpaRepositories in multi module spring boot project

I am trying to move break up a small java spring boot microservices project into a multi-module Gradle project. 我正在尝试将一个小的java spring boot microservices项目分解为一个多模块Gradle项目。

When I have worked on my own projects in the past I have leaned towards having a package for every type of component ie controller, entity, repository, model, service, configuration, datasource, facade... etc. 在过去从事自己的项目时,我倾向于为每种类型的组件(例如,控制器,实体,存储库,模型,服务,配置,数据源,Facade等)提供一个程序包。

Now I have realised 2 things... 1) I would prefer to have a organise my project by domain area NOT component types 2) I should use modules, not packages to organise my project. 现在我已经意识到了两件事... 1)我希望按领域区域来组织我的项目,而不是组件类型2)我应该使用模块而不是包来组织我的项目。

Now most things seem to work like this except the fact that because I don't have all my spring repositories in one package, I cannot use @EnableJpaRepositories annotation. 现在大多数事情看起来都像这样工作,除了事实是,因为我没有在一个软件包中存储所有的Spring信息库,所以无法使用@EnableJpaRepositories批注。 I know in a purely package based project I can use it in a package higher in the hierarchy and it would scan all packages below it and pick out any repositories. 我知道在一个完全基于包的项目中,我可以在层次结构较高的包中使用它,它将扫描它下面的所有包并挑选任何存储库。

I'm not sure how to get around this without having a single package that contains all the repositories. 我不确定在没有包含所有存储库的单个软件包的情况下如何解决此问题。

I almost always organised my projects using only packages so I accept that I may just be misunderstanding the implications of using modules. 我几乎总是只使用包来组织项目,所以我承认我可能只是误解了使用模块的含义。

Any guidance would be appreciated. 任何指导将不胜感激。

I've faced with the same issue and I've found the answer here: https://github.com/spring-projects/spring-boot/issues/8134 . 我遇到了同样的问题,并且在这里找到了答案: https : //github.com/spring-projects/spring-boot/issues/8134

You need to add AutoConfigurationPackage annotation. 您需要添加AutoConfigurationPackage批注。 One more thing - I use org.springframework.boot.autoconfigure.EnableAutoConfiguration configuration in spring.factories resource. 还有一件事-我在spring.factories资源中使用org.springframework.boot.autoconfigure.EnableAutoConfiguration配置。 It give me possiblity to autoload a module if it added just to runtime dependencies. 如果仅将模块添加到运行时依赖项,则可以自动加载模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM