【发布时间】:2017-08-05 17:37:02
【问题描述】:
我创建了一个具有以下配置的项目:
faces-config.xml
<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>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
web.xml
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
和 pom.xml
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>2.2</version>
</dependency>
UserQuery.java
@Component("userQuery")
@SpringViewScope
public class UserQuery implements Serializable
{
private String test = "test";
//getter, setter for test
}
test.xhtml
#{userQuery} // this works, returns userquery object
#{userQuery.test} //throw null pointer exception
例外:
SEVERE: Error Rendering View[/test.xhtml]
javax.el.ELException: /test.xhtml: null
at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:90)
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:207)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1899)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1899)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:451)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at org.ocpsoft.rewrite.faces.RewriteViewHandler.renderView(RewriteViewHandler.java:186)
Caused by: java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
at java.beans.Introspector.isAssignable(Introspector.java:809)
PS:当我删除 SpringBeanFacesELResolver 并使用 jsf @ManagedBean 而不是 @component #{userQuery.test} 也可以,但我不想使用这种方式。
弹簧有什么问题?
我使用的是 tomcat 8.5.16
【问题讨论】: