Spring Data JPA + Guice错误:使用@EnableTransactionManagement注解时,没有类型的主要bean定义

我在Play Framework(Java版本)项目中使用Kotlin 1.1.4-3和Guice和Spring Data JPA 2.0.0.RELEASE。 Play Framework版本是2.5.8。

我使用了spring-projects / spring-guice库,特别是将Spring配置类注册为Guice模块的方法 ,将Spring和Guice集成为Play Framework的DI库。

我将一个接口声明为Spring服务的基础。 语法是Kotlin语言。

interface PersonPresenceManagement { fun autoGenerateOrUpdatePersonPresences(companyInfo: CompanyInfo) fun generatePersonPresence(currentUser: SalaryUser, userId: Long, logPeriodId: Long): Result fun saveOrUpdateDailyReport(currentUser: SalaryUser, personPresenceDbId: Long, dailyReport: DailyReport): Result } 

正如Spring Data JPA文档中提到的:

改变交易行为的另一种可能性是使用通常覆盖多个存储库的外观或服务实现。 其目的是为非CRUD操作定义事务边界:

我实现了PersonPresenceManagement接口:

 @Service open class PersonPresenceManagementImpl @Inject constructor(...) : PersonPresenceManagement { @Transactional override fun generatePersonPresence(currentUser: SalaryUser, userId: Long, logPeriodId: Long): Result { ... } @Transactional override fun autoGenerateOrUpdatePersonPresences(companyInfo: CompanyInfo) { ... } @Transactional override fun saveOrUpdateDailyReport(currentUser: SalaryUser, personPresenceDbId: Long, dailyReport: DailyReport): Result { ... } } 

但是当运行应用程序,它会引发这个错误:

 org.springframework.beans.BeanInstantiationException: Failed to instantiate [ir.iais.playCommons.security.handlers.GlobalDeadboltHandler]: Constructor threw exception; nested exception is com.google.inject.ProvisionException: Unable to provision, see the following errors: Caused by: com.google.inject.ProvisionException: Unable to provision, see the following errors: 1) No primary bean definition for type: class ir.iais.salary.services.impl.PersonPresenceManagementImpl at spring-guice (via modules: com.google.inject.util.Modules$OverrideModule -> ir.iais.playCommons.settings.SpringDataJpaModule) while locating ir.iais.salary.services.PersonPresenceManagement for parameter 10 at controllers.PersonPresenceCtrl.<init>(PersonPresenceCtrl.kt:37) while locating controllers.PersonPresenceCtrl for parameter 6 at router.Routes.<init>(Routes.scala:112) while locating router.Routes while locating play.api.inject.RoutesProvider while locating play.api.routing.Router for parameter 0 at play.api.http.JavaCompatibleHttpRequestHandler.<init>(HttpRequestHandler.scala:200) while locating play.api.http.JavaCompatibleHttpRequestHandler while locating play.api.http.HttpRequestHandler for parameter 4 at play.api.DefaultApplication.<init>(Application.scala:221) at play.api.DefaultApplication.class(Application.scala:221) while locating play.api.DefaultApplication while locating play.api.Application for parameter 0 at play.DefaultApplication.<init>(DefaultApplication.java:30) at play.DefaultApplication.class(DefaultApplication.java:30) while locating play.DefaultApplication while locating play.Application for parameter 1 at be.objectify.deadbolt.java.ExecutionContextProvider.<init>(ExecutionContextProvider.java:40) at be.objectify.deadbolt.java.DeadboltModule.executionContextProvider(DeadboltModule.java:55): Binding(class be.objectify.deadbolt.java.ExecutionContextProvider to self in interface javax.inject.Singleton) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1) while locating be.objectify.deadbolt.java.ExecutionContextProvider 1 error at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1025) at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1051) at org.springframework.guice.module.GuiceAutowireCandidateResolver$1.getTarget(GuiceAutowireCandidateResolver.java:81) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673) at be.objectify.deadbolt.java.ExecutionContextProvider$$EnhancerBySpringCGLIB$$3cfcfcc2.get(<generated>) at be.objectify.deadbolt.java.AbstractDeadboltHandler.<init>(AbstractDeadboltHandler.java:42) at ir.iais.playCommons.security.handlers.GlobalDeadboltHandler.<init>(GlobalDeadboltHandler.kt:21) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 

我甚至把@Primary注释放在PersonPresenceManagementImpl类的上面,但是它不起作用。 我很困惑。 我能做什么?


编辑:

我发现如果从@Configuration类中删除@EnableTransactionManagement批注或从PersonPresenceManagementImpl方法中删除@Transactional批注,此异常将消失。 看来在弹簧配置中启用事务管理时存在一个错误。 负责这个bug的库似乎是spring-projects / spring-guice