0

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

play.api.Application$$anon$1: 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$2$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:261)
[play_2.10.jar:2.2.2-RC1]

at
play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$2$$anonfun$applyOrElse$3.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$2.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$8.apply(JavaAction.scala:80)
~[play_2.10.jar:2.2.2-RC1]

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

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

4

1 回答 1

0

我对 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,这可能是个问题。希望能帮助到你。

于 2015-03-17T14:42:30.743 回答