javax.el.PropertyNotFoundException:无法到达目标,标识符“登录"解析为空Spring + JSF [英] javax.el.PropertyNotFoundException : Target Unreachable, identifier 'login' resolved to null Spring + JSF

查看:126
本文介绍了javax.el.PropertyNotFoundException:无法到达目标,标识符“登录"解析为空Spring + JSF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法解决因@Autowired服务获取null而导致的问题.这是我的代码.

I can't resolve my problem for getting null with my @Autowired service. Here's my code.

我的配置文件

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>

    <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:p="http://www.springframework.org/schema/p"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.2.xsd 
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx.xsd">

    <tx:annotation-driven transaction-manager="transactionManager"/>
    <context:annotation-config/>
    <context:component-scan base-package="com.vulcan.controller.login" />
    <context:component-scan base-package="com.vulcan.service.login" />
    <context:component-scan base-package="com.vulcan.dao.tenant" /> ........

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <context-param>
         <param-name>contextConfigLocation</param-name>
         <param-value>/WEB-INF/applicationContext.xml</param-value>
     </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>....

faces-config.xml

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
    <application>
        <variable-resolver>
            org.springframework.web.jsf.DelegatingVariableResolver
        </variable-resolver>
    </application>
    <application>
        <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
    </application>........

我的代码

LoginServiceImpl.java

@Service
public class LoginServiceImpl implements LoginService{

    @Autowired
    TenantDao tenantDao;

    @Transactional
    @Override
    public String getTenantIdentifier(String email, String password) { ....

LoginController.java

@Component
@Scope("session")
@Qualifier("login")
public class LoginController  {

    private String email;
    private String password;
    private String tenantId;

    @Autowired 
    LoginService loginService;

    public void doLogin() {
        this.tenantId = loginService.getTenantIdentifier(email, password); ..

login.xhtml

<ui:define name="content">
    <h:form id="form">   
        <p:growl id="growl" showDetail="true" life="3000" />  
        <h:panelGrid columns="2" cellpadding="5">  
            <h:outputLabel for="username" value="Username:" />  
            <p:inputText value="#{login.email}" id="username" required="true" label="username"/>
            <h:outputLabel for="password" value="Password:" />  
            <p:inputText value="#{login.password}" id="password" required="true" label="password" type="password" />  
            <f:facet name="footer">  
                <p:commandButton id="loginButton" value="Login" update="growl" action="#{login.doLogin()}"/>  
            </f:facet>  
        </h:panelGrid>  
    </h:form>           
</ui:define>

因此,我选择使用Spring来管理我的所有bean. 这是我为解决问题所做的工作(但仍然没有结果)

So I choose to use Spring to manage all of my beans. Here's what I've done to resolve my problem (but still no result)

  1. 我试图将JSF @ManagedBean注入到LoginController中,而将@ManagedProperty注入到LoginService中.调用doLogin()后,我得到了空指针.它说LoginService具有空指针.

  1. I tried to use inject JSF @ManagedBean to LoginController, and @ManagedProperty for LoginService. I got null pointer after invoke doLogin(). It said LoginService has null pointer.

之后,如上所示,我尝试对LoginController使用Spring注入,然后出现此错误.

After that I tried to use Spring injection to LoginController as you can see above, than I got this error.

/login.xhtml @ 21,109 value =#{login.email}":无法到达目标,标识符"login"解析为空

/login.xhtml @21,109 value="#{login.email}": Target Unreachable, identifier 'login' resolved to null

任何人都可以帮助我吗?我已经在该论坛上关注并尝试了许多建议,但没有任何帮助.

Anyone can help me ? I already follow and try many suggestion in this forum, but nothing's work.

推荐答案

最后我明白了,我只需要删除@Qualifier注释并将@Component注释编辑为@Component("login").

Finally i figured it out, i just need to remove @Qualifier annotation and edit @Component annotation to @Component("login").

多么愚蠢的错误...

What a silly mistakes...

这篇关于javax.el.PropertyNotFoundException:无法到达目标,标识符“登录"解析为空Spring + JSF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆