0

I'm creating a backend service implementation for a bunch of interfaces and to have the cleanest code possible, I decided to move to Constructor based DI instead of Field based, but it gave me headaches.

Using WebLogic 12.1.3, this class gets instantiated properly:

@Stateless(name = "MenuService")
@Slf4j
public class MenuFacade implements MenuService {

    @Inject
    private MenuRepository menuRepository;

    @Inject
    private MenuMapper menuMapper;

    public MenuFacade(MenuRepository menuRepository, MenuMapper menuMapper) {
        this.menuRepository = menuRepository;
        this.menuMapper = menuMapper;
    }

    public MenuFacade() {
    }

    @Override
    @Transactional
    public List<MenuDto> getMenuList() {

        log.trace("Fetching Menu entities from database");
        List<MenuEntity> menuEntities = menuRepository.findAll();
        log.trace("Menu entities: {}", menuEntities);

        return menuEntities.stream().map(menuMapper::menuEntityToMenuDto).collect(Collectors.toList());
    }
}

However, when I try to refactor it like this:

@Stateless(name = "MenuService")
@Slf4j
public class MenuFacade implements MenuService {

    private MenuRepository menuRepository;

    private MenuMapper menuMapper;

    @Inject
    public MenuFacade(MenuRepository menuRepository, MenuMapper menuMapper) {
        this.menuRepository = menuRepository;
        this.menuMapper = menuMapper;
    }

    public MenuFacade() {
    }

    @Override
    @Transactional
    public List<MenuDto> getMenuList() {

        log.trace("Fetching Menu entities from database");
        List<MenuEntity> menuEntities = menuRepository.findAll();
        log.trace("Menu entities: {}", menuEntities);

        return menuEntities.stream().map(menuMapper::menuEntityToMenuDto).collect(Collectors.toList());
    }
}

I get an exception during deployment saying:

####<Nov 7, 2018 5:17:36,164 PM GMT> <Error> <Deployer> <6738a70423ff> <backend> <[ACTIVE] ExecuteThread: '14' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <18022f2f-7d83-46d9-8868-1d1253f0571a-00000032> <1541611
056164> <[severity-value: 8] [rid: 0] [partition-id: 0] [partition-name: DOMAIN] > <BEA-149265> <Failure occurred in the execution of deployment request with ID "2093877349563649" for task "106" on [partition-name: DOMAIN]. Error is: "we
blogic.management.DeploymentException: CDI deployment failure:null"
weblogic.management.DeploymentException: CDI deployment failure:null
        at com.oracle.injection.integration.CDIAppDeploymentExtension.initCdi(CDIAppDeploymentExtension.java:95)
        at com.oracle.injection.integration.CDIAppDeploymentExtension.activate(CDIAppDeploymentExtension.java:43)
        at weblogic.application.internal.flow.AppDeploymentExtensionFlow.activate(AppDeploymentExtensionFlow.java:39)
        at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:752)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
        at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:262)
        at weblogic.application.internal.EarDeployment.activate(EarDeployment.java:66)
        at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:165)
        at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:90)
        at weblogic.deploy.internal.targetserver.operations.AbstractOperation.activate(AbstractOperation.java:631)
        at weblogic.deploy.internal.targetserver.operations.ActivateOperation.activateDeployment(ActivateOperation.java:171)
        at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doCommit(ActivateOperation.java:121)
        at weblogic.deploy.internal.targetserver.operations.AbstractOperation.commit(AbstractOperation.java:348)
        at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentCommit(DeploymentManager.java:907)
        at weblogic.deploy.internal.targetserver.DeploymentManager.activateDeploymentList(DeploymentManager.java:1468)
        at weblogic.deploy.internal.targetserver.DeploymentManager.handleCommit(DeploymentManager.java:459)
        at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.commit(DeploymentServiceDispatcher.java:181)
        at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doCommitCallback(DeploymentReceiverCallbackDeliverer.java:217)
        at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$100(DeploymentReceiverCallbackDeliverer.java:14)
        at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$2.run(DeploymentReceiverCallbackDeliverer.java:69)
        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)
Caused By: java.lang.NullPointerException
        at org.jboss.weld.injection.InjectionPointFactory.getParameterInjectionPoints(InjectionPointFactory.java:250)
        at org.jboss.weld.injection.AbstractCallableInjectionPoint.<init>(AbstractCallableInjectionPoint.java:52)
        at org.jboss.weld.injection.ConstructorInjectionPoint.<init>(ConstructorInjectionPoint.java:63)
        at org.jboss.weld.injection.InjectionPointFactory.createConstructorInjectionPoint(InjectionPointFactory.java:175)
        at org.jboss.weld.injection.producer.SubclassedComponentInstantiator.forSubclassedEjb(SubclassedComponentInstantiator.java:58)
        at org.jboss.weld.injection.producer.ejb.SessionBeanInjectionTarget.initInstantiator(SessionBeanInjectionTarget.java:86)
        at org.jboss.weld.injection.producer.BasicInjectionTarget.<init>(BasicInjectionTarget.java:98)
        at org.jboss.weld.injection.producer.BasicInjectionTarget.<init>(BasicInjectionTarget.java:82)
        at org.jboss.weld.injection.producer.BeanInjectionTarget.<init>(BeanInjectionTarget.java:58)
        at org.jboss.weld.injection.producer.ejb.SessionBeanInjectionTarget.<init>(SessionBeanInjectionTarget.java:67)
        at org.jboss.weld.injection.producer.ejb.SessionBeanInjectionTarget.of(SessionBeanInjectionTarget.java:61)
        at org.jboss.weld.manager.InjectionTargetFactoryImpl.chooseInjectionTarget(InjectionTargetFactoryImpl.java:105)
        at org.jboss.weld.manager.InjectionTargetFactoryImpl.createInjectionTarget(InjectionTargetFactoryImpl.java:86)
        at org.jboss.weld.bean.SessionBean.<init>(SessionBean.java:89)
        at org.jboss.weld.bean.SessionBean.of(SessionBean.java:77)
        at org.jboss.weld.bootstrap.AbstractBeanDeployer.createSessionBean(AbstractBeanDeployer.java:292)
        at org.jboss.weld.bootstrap.BeanDeployer.createClassBeans(BeanDeployer.java:202)
        at org.jboss.weld.bootstrap.BeanDeployment.createBeans(BeanDeployment.java:256)
        at org.jboss.weld.bootstrap.WeldStartup.deployBeans(WeldStartup.java:397)
        at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:83)
        at com.oracle.injection.provider.weld.WeldInjectionContainer.deploy(WeldInjectionContainer.java:143)
        at com.oracle.injection.integration.CDIAppDeploymentExtension.initCdi(CDIAppDeploymentExtension.java:82)
        at com.oracle.injection.integration.CDIAppDeploymentExtension.activate(CDIAppDeploymentExtension.java:43)
        at weblogic.application.internal.flow.AppDeploymentExtensionFlow.activate(AppDeploymentExtensionFlow.java:39)
        at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:752)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
        at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:262)
        at weblogic.application.internal.EarDeployment.activate(EarDeployment.java:66)
        at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:165)
        at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:90)
        at weblogic.deploy.internal.targetserver.operations.AbstractOperation.activate(AbstractOperation.java:631)
        at weblogic.deploy.internal.targetserver.operations.ActivateOperation.activateDeployment(ActivateOperation.java:171)
        at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doCommit(ActivateOperation.java:121)
        at weblogic.deploy.internal.targetserver.operations.AbstractOperation.commit(AbstractOperation.java:348)
        at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentCommit(DeploymentManager.java:907)
        at weblogic.deploy.internal.targetserver.DeploymentManager.activateDeploymentList(DeploymentManager.java:1468)
        at weblogic.deploy.internal.targetserver.DeploymentManager.handleCommit(DeploymentManager.java:459)
        at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.commit(DeploymentServiceDispatcher.java:181)
        at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doCommitCallback(DeploymentReceiverCallbackDeliverer.java:217)
        at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$100(DeploymentReceiverCallbackDeliverer.java:14)
        at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$2.run(DeploymentReceiverCallbackDeliverer.java:69)
        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)

Is it a bug with WebLogic? Why is one working, but the other doesn't?

László Stahorszki
  • 1,102
  • 7
  • 23

1 Answers1

0

From this link http://docs.jboss.org/weld/reference/latest/en-US/html_single/#_injection_points

Dependency injection always occurs when the bean instance is first instantiated by the container. Simplifying just a little, things happen in this order:

First, the container calls the bean constructor (the default constructor or the one annotated @Inject), to obtain an instance of the bean. Next, the container initializes the values of all injected fields of the bean. Next, the container calls all initializer methods of bean (the call order is not portable, don’t rely on it). Finally, the @PostConstruct method, if any, is called.

So looks like if you have constructor injection you have to remove no-arg constructor.

Community
  • 1
  • 1
Ivan
  • 8,508
  • 2
  • 19
  • 30