【问题标题】:Dependency Injection error after upgrading to Weblogic 12c升级到 Weblogic 12c 后出现依赖注入错误
【发布时间】:2017-07-26 20:55:25
【问题描述】:

我最近从 Weblogic 11g 升级到了 12c。当 MyOtherBean 尝试使用 @EJB 注释注入 MyStartupBean 时,在标准输出中出现此错误:

 [exec] <Mar 6, 2017, 9:39:45,547 AM EST> <Warning> <EJB> <BEA-010065> <MessageDrivenBean threw an Exception in onMessage(). The exception is:
 [exec]  javax.enterprise.inject.InjectionException: Exception trying to inject java EE injection point into class: com.foo.My.cache.ejb.MyOtherBean..
 [exec] javax.enterprise.inject.InjectionException: Exception trying to inject java EE injection point into class: com.foo.My.cache.ejb.MyOtherBean.
 [exec]     at com.oracle.injection.integration.ModuleContainerIntegrationService.performJavaEEInjection(ModuleContainerIntegrationService.java:405)
 [exec]     at com.oracle.injection.provider.weld.WeldInjectionServicesAdapter.aroundInject(WeldInjectionServicesAdapter.java:49)
 [exec]     at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:46)
 [exec]     at org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:72)
 [exec]     at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:121)
 [exec]     Truncated. see log file for complete stacktrace
 [exec] Caused By: com.bea.core.repackaged.springframework.beans.factory.BeanCreationException: Dependency injection failure: can't inject the value 'com.foo.My.common.ejb.MyStartupBean_pqx8ri_Impl@39dc616' into the field 'private com.foo.My.common.interfaces.MyStartup com.foo.My.cache.ejb.MyOtherBean.startup'; nested exception is java.lang.IllegalArgumentException: Can not set com.foo.My.common.interfaces.MyStartup field com.foo.My.cache.ejb.MyOtherBean.startup to com.sun.proxy.$Proxy352
 [exec]     at com.oracle.pitchfork.inject.FieldInjection.apply(FieldInjection.java:45)
 [exec]     at com.oracle.pitchfork.inject.Jsr250Metadata.performInjection(Jsr250Metadata.java:228)
 [exec]     at com.oracle.pitchfork.inject.Jsr250Metadata.applyInjections(Jsr250Metadata.java:215)
 [exec]     at com.oracle.pitchfork.inject.Jsr250Metadata.inject(Jsr250Metadata.java:197)
 [exec]     at com.oracle.injection.integration.ModuleContainerIntegrationService.performJavaEEInjection(ModuleContainerIntegrationService.java:398)
 [exec]     Truncated. see log file for complete stacktrace
 [exec] Caused By: java.lang.IllegalArgumentException: Can not set com.foo.My.common.interfaces.MyStartup field com.foo.My.cache.ejb.MyOtherBean.startup to com.sun.proxy.$Proxy352
 [exec]     at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
 [exec]     at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
 [exec]     at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
 [exec]     at java.lang.reflect.Field.set(Field.java:764)
 [exec]     at com.oracle.pitchfork.inject.FieldInjection.apply(FieldInjection.java:43)
 [exec]     Truncated. see log file for complete stacktrace

这是 MyStartup 界面:

@Remote
public interface MyStartup extends my.base.BaseObj
{
   public java.util.Collection getX( ) ;
   public java.util.Collection getY( ) ;
}

还有 MyStartupBean ejb:

@Stateless
@CallByReference
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
@TransactionManagement(TransactionManagementType.CONTAINER)
public class MyStartupBean extends BaseSessionBean implements MyStartup
{
   public java.util.Collection getX( ){
        //do stuff
   }

   public java.util.Collection getY( ){
        //do stuff
   }
}

最后是调用 MyStartup 接口/MyStartupBean ejb 的 MyOtherBean 类:

@MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic") }, mappedName="jms/CacheRefreshTopic")
@MessageDestinationConfiguration(connectionFactoryJNDIName="jms/CacheRefreshCF")
@TransactionAttribute(value=TransactionAttributeType.SUPPORTS)
@TransactionManagement(value=TransactionManagementType.CONTAINER)
public class MyOtherBean implements MessageListener
{
    ...
    @EJB private MyStartup startup;
    ...
}

【问题讨论】:

    标签: java dependency-injection weblogic weblogic12c java-ee-7


    【解决方案1】:

    为什么 MyStartup 被标记为 @Remote 但您正尝试使用 @EJB 注释将他的实现者作为本地 bean 注入?

    我将标记注解改为@Local后,代码已经开始成功部署在我的Oracle WebLogic 12.2.1.2.0域上。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-26
      • 2018-06-14
      • 1970-01-01
      • 2016-05-12
      • 1970-01-01
      • 1970-01-01
      • 2013-09-07
      相关资源
      最近更新 更多