简体   繁体   中英

javax.faces.el.EvaluationException: java.lang.NullPointerException error

I'm geeting javax.faces.el.EvaluationException: java.lang.NullPointerException error when I'm trying to run my Spring-jsf application. I tried debugging the code and found that "serviceIfc" is not being initialized and is null, I'm not able to figure out how to resolve it. Please help. Here is my LoginBean.java

@ManagedBean
public class LoginBean {
private String uname;
private String pwd;
private LoginServiceIfc serviceIfc;

public LoginServiceIfc getServiceIfc() {
return serviceIfc;
}
@Autowired
    public void setServiceIfc(LoginServiceIfc serviceIfc) {
this.serviceIfc = serviceIfc;
System.out.println("setServiceIfc method inside LOginBean running...");
}

public String getUname() {
    return uname;
}

public void setUname(String uname) {
    this.uname = uname;
}

public String getPwd() {
    return pwd;
}

public void setPwd(String pwd) {
    this.pwd = pwd;
}

public String doLogin()
{
    if(uname=="" || pwd=="")
    {
        return "fail";
    }
    else
    {
        String str=serviceIfc.doLogin(uname,pwd);
        return str;
    }
}

}

part of the applicationcontext.xml is as follows:

<bean id="loginBean" class="com.bean.LoginBean" scope="session">
<property name="serviceIfc">
    <ref bean="loginServiceIfc" />
</property>      
</bean>

<bean id="loginServiceIfc" class="com.service.serviceImpl.login.LoginServiceImpl" scope="session">
<property name="daoIfc">
    <ref bean="loginDaoIfc" />
</property>
</bean>

<bean id="loginDaoIfc" class="com.dao.daoImpl.login.LoginDaoImpl" scope="session">
</bean>

Below is the full error message:

Apr 25, 2013 1:36:14 AM com.sun.faces.lifecycle.InvokeApplicationPhase execute
WARNING: #{loginBean.doLogin}: java.lang.NullPointerException
javax.faces.FacesException: #{loginBean.doLogin}: java.lang.NullPointerException
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at com.controller.LoginServlet.service(LoginServlet.java:34)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
... 25 more
Caused by: java.lang.NullPointerException
at com.bean.LoginBean.doLogin(LoginBean.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.el.parser.AstValue.invoke(AstValue.java:264)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
... 26 more

Annotations from the two frameworks you employ can't be used together. Either let the bean be managed by JSF with @ManagedBean / @ManagedProperty , or by Spring with @Component / @Autowired .

The way you have it now the dependency injection can't be prerformed, hence the NullPointerException you faced.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM