使用Spring Bean和构造函数注入的java.lang.NullPointerException

时间:2015-06-15 20:35:03

标签: dependency-injection nullpointerexception

我在一个类中得到一个NullPointerException,我无法解释原因。它使用Spring Framework 2.5.6版本,它是一个Spring bean。 70处的代码行是

userPreferenceService = (UserPreferenceService) MyAppContext.getApplicationContext().getBean("userPreferenceService");

应用程序上下文有这个

    <bean id="userPreferenceService" class="com.service.PreferenceServiceImpl">
    <constructor-arg ref="displayFieldsDAO" />
    <constructor-arg ref="displayPrefDAO" />
    <constructor-arg ref="savedQueryDAO" />
    <constructor-arg ref="userDAO" />
</bean>

我无法弄清楚空指针的来源。是因为它无法访问ApplicationContext吗?如果没有,这是它无法访问的唯一的春豆,许多其他的豆都很好。

或许它是一个返回null的构造函数args?

&#13;
&#13;
2015-06-15 16:01:39,184 ERROR (com.ui.util.CreateUserSSOFilter:74) - 
java.lang.NullPointerException
        at com.ui.util.CreateUserSSOFilter.init(CreateUserSSOFilter.java
:70)
        at weblogic.servlet.internal.FilterManager$FilterInitAction.run(FilterManager.java:
343)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.ja
va:321)
        at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
        at weblogic.servlet.internal.FilterManager.loadFilter(FilterManager.java:96)
        at weblogic.servlet.internal.FilterManager.preloadFilters(FilterManager.java:57)
        at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletCon
text.java:1872)
        at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:3
154)
        at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1518)
        at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:484)
        at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.ja
va:425)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:
52)
        at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.jav
a:119)
        at weblogic.application.internal.flow.ScopedModuleDriver.start(ScopedModuleDriver.j
ava:200)
        at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInv
oker.java:247)
        at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.ja
va:425)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:
52)
        at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.jav
a:119)
        at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.ja
va:27)
        at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:671)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:
52)
        at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:212)
        at weblogic.application.internal.EarDeployment.activate(EarDeployment.java:59)
        at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChe
cker.java:161)
        at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerI
nvoker.java:79)
        at weblogic.deploy.internal.targetserver.operations.AbstractOperation.activate(Abst
ractOperation.java:569)
        at weblogic.deploy.internal.targetserver.operations.ActivateOperation.activateDeplo
yment(ActivateOperation.java:150)
        at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doCommit(Acti
vateOperation.java:116)
        at weblogic.deploy.internal.targetserver.operations.AbstractOperation.commit(Abstra
ctOperation.java:323)
        at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentCommit(D
eploymentManager.java:844)
        at weblogic.deploy.internal.targetserver.DeploymentManager.activateDeploymentList(D
eploymentManager.java:1253)
        at weblogic.deploy.internal.targetserver.DeploymentManager.handleCommit(DeploymentM
anager.java:440)
        at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.commit(Deploym
entServiceDispatcher.java:163)
        at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDelivere
r.doCommitCallback(DeploymentReceiverCallbackDeliverer.java:195)
        at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDelivere
r.access$100(DeploymentReceiverCallbackDeliverer.java:13)
        at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDelivere
r$2.run(DeploymentReceiverCallbackDeliverer.java:68)
        at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManage
rImpl.java:545)
        at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
        at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
&#13;
&#13;
&#13;

0 个答案:

没有答案