范围冲突,直到批处理作业完成?

时间:2018-09-26 14:15:40

标签: cdi hibernate-search jsr352 jberet weld-se

技术栈:

  • JBeret(核心,se)1.3.0。最终
  • 休眠搜索(orm,jsr352-core,jsr352-jberet)5.10.4。最终
  • 焊接(servlet-core,se-core)3.0.5.Final

如果我触发

BatchRuntime.getJobOperator().start( MassIndexingJob.NAME, MassIndexingJob.parameters().forEntity(getDomainObjectClass()).build() );

然后我遇到的情况是,在批处理作业完成之前,无法访问批处理作业的任何RequestScopedSessionScoped的CDI组件外部

如何解决此问题?

堆栈跟踪的一部分

 Caused by: org.jboss.weld.contexts.ContextNotActiveException: WELD-001303: No active contexts for scope type javax.enterprise.context.RequestScoped
    at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:647) ~[weld-core-impl-3.0.5.Final.jar:3.0.5.Final]
    at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.getIfExists(ContextualInstanceStrategy.java:89) ~[weld-core-impl-3.0.5.Final.jar:3.0.5.Final]
    at org.jboss.weld.bean.ContextualInstanceStrategy$CachingContextualInstanceStrategy.getIfExists(ContextualInstanceStrategy.java:164) ~[weld-core-impl-3.0.5.Final.jar:3.0.5.Final]
    at org.jboss.weld.bean.ContextualInstance.getIfExists(ContextualInstance.java:63) ~[weld-core-impl-3.0.5.Final.jar:3.0.5.Final]
    at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:87) ~[weld-core-impl-3.0.5.Final.jar:3.0.5.Final]
    at org.jboss.weld.bean.proxy.ProxyMethodHandler.getInstance(ProxyMethodHandler.java:131) ~[weld-core-impl-3.0.5.Final.jar:3.0.5.Final]
    at foo.bar.Baz$Proxy$_$$_WeldClientProxy.getFoo(Unknown Source) ~[classes/:na]

带注释的@ActivateRequestContext在启动/部署时产生此堆栈跟踪

 Caused by: org.jboss.weld.exceptions.WeldException: WELD-001524: Unable to load proxy class for bean Managed Bean [class foo.bar.Bean] with qualifiers [@Any @Default] with class class foo.bar.Bean using classloader ParallelWebappClassLoader
  context: foobar
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@58a9760d

    at org.jboss.weld.bean.proxy.ProxyFactory.getProxyClass(ProxyFactory.java:370)
    at org.jboss.weld.injection.producer.SubclassedComponentInstantiator.createEnhancedSubclass(SubclassedComponentInstantiator.java:113)
    at org.jboss.weld.injection.producer.SubclassedComponentInstantiator.initEnhancedSubclass(SubclassedComponentInstantiator.java:86)
    at org.jboss.weld.injection.producer.SubclassedComponentInstantiator.<init>(SubclassedComponentInstantiator.java:79)
    at org.jboss.weld.injection.producer.SubclassedComponentInstantiator.forInterceptedDecoratedBean(SubclassedComponentInstantiator.java:63)
    at org.jboss.weld.injection.producer.BeanInjectionTarget.initializeAfterBeanDiscovery(BeanInjectionTarget.java:121)
    at org.jboss.weld.injection.producer.InjectionTargetInitializationContext.initialize(InjectionTargetInitializationContext.java:42)
    at org.jboss.weld.injection.producer.InjectionTargetService.initialize(InjectionTargetService.java:63)
    at org.jboss.weld.bootstrap.WeldStartup.deployBeans(WeldStartup.java:475)
    at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:86)
    at org.jboss.weld.environment.servlet.WeldServletLifecycle.initialize(WeldServletLifecycle.java:236)
    at org.jboss.weld.environment.servlet.EnhancedListener.onStartup(EnhancedListener.java:62)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5245)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 42 more
Caused by: org.jboss.weld.exceptions.WeldException: Cannot load variable at 0. Local Variables: Local Variables: []
    at org.jboss.weld.bean.proxy.InterceptedSubclassFactory.addMethodsFromClass(InterceptedSubclassFactory.java:262)
    at org.jboss.weld.bean.proxy.InterceptedSubclassFactory.addMethods(InterceptedSubclassFactory.java:136)
    at org.jboss.weld.bean.proxy.ProxyFactory.createProxyClass(ProxyFactory.java:449)
    at org.jboss.weld.bean.proxy.ProxyFactory.getProxyClass(ProxyFactory.java:362)
    ... 55 more
Caused by: org.jboss.classfilewriter.InvalidBytecodeException: Cannot load variable at 0. Local Variables: Local Variables: []
    at org.jboss.classfilewriter.code.CodeAttribute.aload(CodeAttribute.java:196)
    at org.jboss.weld.bean.proxy.RunWithinInterceptionDecorationContextGenerator.startIfNotOnTop(RunWithinInterceptionDecorationContextGenerator.java:71)
    at org.jboss.weld.bean.proxy.RunWithinInterceptionDecorationContextGenerator.runStartIfNotOnTop(RunWithinInterceptionDecorationContextGenerator.java:148)
    at org.jboss.weld.bean.proxy.InterceptedSubclassFactory.addMethodsFromClass(InterceptedSubclassFactory.java:200)
    ... 58 more

1 个答案:

答案 0 :(得分:0)

我不知道JBeret究竟能做什么,但是开箱即用的Weld SE无法不激活请求上下文(或会话上下文),从而导致您看到异常。原因是SE中没有HTTP请求(或会话),因此Weld根本不知道何时激活它。

尽管“请求”可以有不同的解释,甚至在SE中也可以是有价值的添加-这就是为什么支持激活请求上下文for instance via interceptor的方法。 我想这是JBeret为您做的事情,这就是为什么bean在这里“起作用”的原因。

因此,为了能够在SE应用程序中使用您的请求范围的bean,您将需要采取额外的步骤。但是请注意,上下文可能与JBeret批处理作业的上下文不同(您不会看到状态完全相同的相同bean),因为我希望JBeret将工作卸载到另一个线程。

相关问题