使用Spring 4.0.1 DI时,无法在Play 2.2.1中配置deadbolt-2

时间:2015-03-16 08:42:54

标签: spring playframework playframework-2.2 deadbolt

我正在使用Play 4.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不要为死锁注释寻找bean?

1 个答案:

答案 0 :(得分: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,这可能会出现问题。希望它有所帮助。