Java 目标不可访问,标识符解析为空,名称、依赖项、导入正确
关于JSF中el标记的使用,我遇到了一个奇怪的问题。我有一个几乎为空的项目,具有以下依赖项:Java 目标不可访问,标识符解析为空,名称、依赖项、导入正确,java,jsf,maven,Java,Jsf,Maven,关于JSF中el标记的使用,我遇到了一个奇怪的问题。我有一个几乎为空的项目,具有以下依赖项: <dependency> <groupId>javax.el</groupId> <artifactId>el-api</artifactId> <version>2.2</version> <scope>compile</scope>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>2.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>cupertino</artifactId>
<version>1.0.10</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.10</version>
</dependency>
web.xml如下所示:
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ApplicationScoped;
@ManagedBean(name = "requester")
@ApplicationScoped
public class UserBean implements Serializable {
public String getRequestIdentificator() {
return requestIdentificator;
}
public void setRequestIdentificator(String requestIdentificator) {
this.requestIdentificator = requestIdentificator;
}
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="DAS_ID">
<display-name>DAS</display-name>
<context-param>
<param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name>
<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
<context-param>
<description>Parameter required by Mojarra 2.0</description>
<param-name>com.sun.faces.allowTextChildren</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.VALIDATE_EMPTY_FIELDS</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>
Tell the runtime where we are in the project development
lifecycle. Valid values are:
Development, UnitTest, SystemTest, or Production.
The runtime will display helpful hints to correct common mistakes
when the value is Development.
</description>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>faces/main.xhtml</welcome-file>
</welcome-file-list>
</web-app>
我已经搜索了错误,常见错误如总结如下:,但这些都不适用。此外,NetBeans能够为我正在做的每件事使用代码完成功能,我还尝试了requestIdentificator以外的其他功能——因此代码似乎编写得完全正确。Bean永远不会被初始化,因此不会调用构造函数中的日志记录,但根据示例,在JSF 2.x中的faces配置中注册Bean是不必要的,我使用的是2.1,所以这不可能是问题所在
我用mvn tomcat7:run运行一切。有人知道如何解决这个问题吗?我经常在使用javax.faces.bean包时遇到同样的问题。尝试导入
import javax.enterprise.context.ApplicationScoped;
而不是
import javax.faces.bean.ApplicationScoped;
使用@Named代替@ManagedBean注释
然后构建并重新部署。看看这是否有帮助问题是我尝试使用mvn tomcat7:run运行它。如果我将war复制到一个普通的tomcat7实例中,它就会工作,如果我使用mvn tomcat7运行它,它也会工作:run war。似乎是maven tomcat插件错误。看起来您的类UserBean没有用于此requestIdentificator属性的getter/setter。检查您的托管bean定义。只需注意,这个问题与maven或您的web.xml文件都没有关系……如果同时获得了requestIdentificationFactor的getter和setter。谢谢你的提示,我会把它们添加到任务中。我不知道问题在哪里,所以我发布了所有我认为可能与问题有关的东西。谢谢你的回答,但我想使用JSF而不是CDI,所以@Named对我来说不是正确的方式,我的依赖关系对CDI来说也不是正确的。
import javax.faces.bean.ApplicationScoped;
import javax.inject.Named;
import javax.enterprise.context.ApplicationScoped;
@Named("requester")
@ApplicationScoped
public class UserBean implements Serializable {