无法在已实现 Spring 4.0.1 DI 的 Play 2.2.1 中配置 deadbolt-2

Unable to configure deadbolt-2 in Play 2.2.1 with Spring 4.0.1 DI already implemented

我正在使用 Play 2.2.1 和 Spring DI 4.0.1。我正在使用 deadbolt-java 授权版本 2.2-RC1。每当我访问任何请求处理程序时 使用 Deadbolt 注释进行注释,例如:@SubjectPresent(handler = BaseDeadboltHandler.class) 我看到 Deadbolt 生成的异常:

play.api.Application$$anon: Execution
exception[[NoSuchBeanDefinitionException: No qualifying bean of type
[be.objectify.deadbolt.java.actions.SubjectPresentAction] is defined]]

at play.api.Application$class.handleError(Application.scala:293)
~[play_2.10.jar:2.2.2-RC1]

at play.api.DefaultApplication.handleError(Application.scala:399)
[play_2.10.jar:2.2.2-RC1]

at
play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$$anonfun$applyOrElse.apply(PlayDefaultUpstreamHandler.scala:261)
[play_2.10.jar:2.2.2-RC1]

at
play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$$anonfun$applyOrElse.apply(PlayDefaultUpstreamHandler.scala:261)
[play_2.10.jar:2.2.2-RC1]

at scala.Option.map(Option.scala:145) [scala-library.jar:na]

at
play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun.applyOrElse(PlayDefaultUpstreamHandler.scala:261)
[play_2.10.jar:2.2.2-RC1]

Caused by:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type
[be.objectify.deadbolt.java.actions.SubjectPresentAction] is defined

at
org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:318)
~[spring-beans-4.0.1.RELEASE.jar:4.0.1.RELEASE]

at
org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:985)
~[spring-context-4.0.1.RELEASE.jar:4.0.1.RELEASE]

at Global.getControllerInstance(Global.java:139) ~[classes/:na]

at
play.core.j.JavaGlobalSettingsAdapter.getControllerInstance(JavaGlobalSettingsAdapter.scala:46)
~[play_2.10.jar:2.2.2-RC1]

at play.core.j.JavaAction$$anonfun.apply(JavaAction.scala:80)
~[play_2.10.jar:2.2.2-RC1]

at play.core.j.JavaAction$$anonfun.apply(JavaAction.scala:77)
~[play_2.10.jar:2.2.2-RC1]

这可能是因为 Spring 正在尝试使用它的 bean 容器来管理门栓 类。这可以避免吗?有什么方法可以告诉 Spring 不要为 deadbolt 注释寻找 bean?

我遇到了与 Security.AuthenticatedAction 类似的问题,我在这里 https://groups.google.com/forum/#!topic/play-framework/gV596rEE_MU 找到了答案。您可以做的最简单的事情就是将 dynamicAction 定义为一个 bean。

@Bean
public be.objectify.deadbolt.java.actions.DynamicAction dynamicAction(){
    return new be.objectify.deadbolt.java.actions.DynamicAction();
}

当然,如果您有多个@DynamicAction,这可能会成为一个问题。希望对你有帮助。