我正在为一堆接口创建一个后端服务实现,并尽可能拥有最干净的代码,我决定转向基于构造函数的 DI 而不是基于字段,但这让我很头疼。
使用 WebLogic 12.1.3,此类被正确实例化:
@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());
}
}
但是,当我尝试像这样重构它时:
@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());
}
}
我在部署期间遇到异常说:
####<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)
它是 WebLogic 的错误吗?为什么一个工作,而另一个不工作?