Weblogic无法在静态字段中注入@PersistenceContext。

huangapple go评论71阅读模式
英文:

Weblogic cannot inject @PersistenceContext in static field

问题

我对Weblogic并不是很熟悉,也许这是一个愚蠢的问题,但我不明白为什么如果持久化上下文将被注入到静态字段中,部署会失败。

@PersistenceContext(unitName = "name")
private static EntityManager em;
java.lang.IllegalArgumentException:"class_name" 中的字段 "em" 被定义为使用注解 @PersistenceContext 的注入目标但是 "em" 不能被声明为静态字段
	at weblogic.j2ee.dd.xml.validator.injectiontarget.BaseValidator.error(BaseValidator.java:132)
	at weblogic.j2ee.dd.xml.validator.injectiontarget.BaseValidator.error(BaseValidator.java:149)
	at weblogic.j2ee.dd.xml.validator.injectiontarget.J2EEValidator.checkModifier(J2EEValidator.java:28)
	at weblogic.j2ee.dd.xml.validator.AbstractAnnotationValidator.checkField(AbstractAnnotationValidator.java:57)
	at weblogic.j2ee.dd.xml.validator.AbstractAnnotationValidator.validate(AbstractAnnotationValidator.java:26)
	at weblogic.j2ee.dd.xml.validator.AnnotationValidatorVisitor.visitInjectionTargetBean(AnnotationValidatorVisitor.java:48)
	at weblogic.j2ee.dd.xml.validator.AnnotationValidatorVisitor.visit(AnnotationValidatorVisitor.java:25)
	at weblogic.descriptor.internal.AbstractDescriptorBean.accept(AbstractDescriptorBean.java:1448)
	at weblogic.descriptor.internal.AbstractDescriptorBean.accept(AbstractDescriptorBean.java:1452)
	at weblogic.descriptor.internal.AbstractDescriptorBean.accept(AbstractDescriptorBean.java:1452)
	at weblogic.descriptor.internal.AbstractDescriptorBean.accept(AbstractDescriptorBean.java:1452)
	at weblogic.descriptor.internal.AbstractDescriptorBean.accept(AbstractDescriptorBean.java:1452)
	at weblogic.j2ee.dd.xml.BaseJ2eeAnnotationProcessor.validate(BaseJ2eeAnnotationProcessor.java:205)
	at weblogic.j2ee.dd.xml.BaseJ2eeAnnotationProcessor.validate(BaseJ2eeAnnotationProcessor.java:197)
	at weblogic.ejb.container.metadata.EjbAnnotationProcessor.processAnnotations(EjbAnnotationProcessor.java:260)
	at weblogic.ejb.container.metadata.EjbDescriptorReaderImpl.processAnnotations(EjbDescriptorReaderImpl.java:364)
	at weblogic.ejb.container.deployer.EJBMetadataHandler.processAnnotations(EJBMetadataHandler.java:164)
	at weblogic.ejb.container.deployer.EJBMetadataHandler.processAnnotations(EJBMetadataHandler.java:157)
	at weblogic.ejb.container.deployer.EJBModule.processAnnotations(EJBModule.java:175)
	at weblogic.ejb.container.deployer.EJBModule.prepare(EJBModule.java:370)
	at weblogic.application.internal.ExtensibleModuleWrapper$PrepareStateChange.next(ExtensibleModuleWrapper.java:295)
	at weblogic.application.internal.ExtensibleModuleWrapper$PrepareStateChange.next(ExtensibleModuleWrapper.java:285)
	at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
	at weblogic.application.internal.ExtensibleModuleWrapper.prepare(ExtensibleModuleWrapper.java:109)
	at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:100)
	at weblogic.application.internal.flow.ModuleStateDriver$1.next(ModuleStateDriver.java:192)
	at weblogic.application.internal.flow.ModuleStateDriver$1.next(ModuleStateDriver.java:187)
	at weblogic.application.utils.StateMachineDriver$ParallelChange.run(StateMachineDriver.java:83)
	at weblogic.work.ContextWrap.run(ContextWrap.java:46)
	at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:670)
	at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:352)
	at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:337)
	at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:57)
	at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)
	at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:644)
	at weblogic.work.ExecuteThread.execute(ExecuteThread.java:415)
	at weblogic.work.ExecuteThread.run(ExecuteThread.java:355)
英文:

I'm not very skilled on Weblogic, and maybe is a stupid question, but I'm unable to understand why the deploy fail if the persistence context will be injected in a static field.

@PersistenceContext(unitName = "name")
private static EntityManager em;
java.lang.IllegalArgumentException: Field "em" in class "class_name" is defined as injection target with annotation @PersistenceContext, but "em" cannot be declared as static field.
at weblogic.j2ee.dd.xml.validator.injectiontarget.BaseValidator.error(BaseValidator.java:132)
at weblogic.j2ee.dd.xml.validator.injectiontarget.BaseValidator.error(BaseValidator.java:149)
at weblogic.j2ee.dd.xml.validator.injectiontarget.J2EEValidator.checkModifier(J2EEValidator.java:28)
at weblogic.j2ee.dd.xml.validator.AbstractAnnotationValidator.checkField(AbstractAnnotationValidator.java:57)
at weblogic.j2ee.dd.xml.validator.AbstractAnnotationValidator.validate(AbstractAnnotationValidator.java:26)
at weblogic.j2ee.dd.xml.validator.AnnotationValidatorVisitor.visitInjectionTargetBean(AnnotationValidatorVisitor.java:48)
at weblogic.j2ee.dd.xml.validator.AnnotationValidatorVisitor.visit(AnnotationValidatorVisitor.java:25)
at weblogic.descriptor.internal.AbstractDescriptorBean.accept(AbstractDescriptorBean.java:1448)
at weblogic.descriptor.internal.AbstractDescriptorBean.accept(AbstractDescriptorBean.java:1452)
at weblogic.descriptor.internal.AbstractDescriptorBean.accept(AbstractDescriptorBean.java:1452)
at weblogic.descriptor.internal.AbstractDescriptorBean.accept(AbstractDescriptorBean.java:1452)
at weblogic.descriptor.internal.AbstractDescriptorBean.accept(AbstractDescriptorBean.java:1452)
at weblogic.j2ee.dd.xml.BaseJ2eeAnnotationProcessor.validate(BaseJ2eeAnnotationProcessor.java:205)
at weblogic.j2ee.dd.xml.BaseJ2eeAnnotationProcessor.validate(BaseJ2eeAnnotationProcessor.java:197)
at weblogic.ejb.container.metadata.EjbAnnotationProcessor.processAnnotations(EjbAnnotationProcessor.java:260)
at weblogic.ejb.container.metadata.EjbDescriptorReaderImpl.processAnnotations(EjbDescriptorReaderImpl.java:364)
at weblogic.ejb.container.deployer.EJBMetadataHandler.processAnnotations(EJBMetadataHandler.java:164)
at weblogic.ejb.container.deployer.EJBMetadataHandler.processAnnotations(EJBMetadataHandler.java:157)
at weblogic.ejb.container.deployer.EJBModule.processAnnotations(EJBModule.java:175)
at weblogic.ejb.container.deployer.EJBModule.prepare(EJBModule.java:370)
at weblogic.application.internal.ExtensibleModuleWrapper$PrepareStateChange.next(ExtensibleModuleWrapper.java:295)
at weblogic.application.internal.ExtensibleModuleWrapper$PrepareStateChange.next(ExtensibleModuleWrapper.java:285)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
at weblogic.application.internal.ExtensibleModuleWrapper.prepare(ExtensibleModuleWrapper.java:109)
at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:100)
at weblogic.application.internal.flow.ModuleStateDriver$1.next(ModuleStateDriver.java:192)
at weblogic.application.internal.flow.ModuleStateDriver$1.next(ModuleStateDriver.java:187)
at weblogic.application.utils.StateMachineDriver$ParallelChange.run(StateMachineDriver.java:83)
at weblogic.work.ContextWrap.run(ContextWrap.java:46)
at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:670)
at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:352)
at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:337)
at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:57)
at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)
at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:644)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:415)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:355)

答案1

得分: 1

@Vincenzo和我是同事,所以我们要告诉您,他通过配置Weblogic在生产模式下解决了这个问题。

原因仍然不清楚,但暂时并不重要,因为...它起作用了!

英文:

@Vincenzo and I are colleagues, so we would inform you that he solved the issue by configuring Weblogic in production mode.

The reason is still obscure, but for the moment it doesn't matter, because... it works!

答案2

得分: 0

不应使用 static 修饰符,应使用非静态变量

英文:

Should not static modifier, use non-static variable

huangapple
  • 本文由 发表于 2020年9月23日 17:20:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/64024812.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定