- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建一个基于 Spring 的 JSF 应用程序,我在其中获取返回 null 的 FacesContext.getCurrentInstance。
这是我的 Java 代码
public static ServletContext getServletContext()
{
return (ServletContext) FacesContext.getCurrentInstance()
.getExternalContext().getContext();
}
这是我错误的堆栈跟踪
SEVERE: Exception sending context initialized event to listener instance of class
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dbSettingsServiceTarget' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.smartcall.service.impl.DbSettingsServiceImpl]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:883)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:839)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3972)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
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.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.smartcall.service.impl.DbSettingsServiceImpl]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:115)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:61)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:877)
... 31 more
Caused by: java.lang.NullPointerException
at com.smartcall.util.FacesUtil.getServletContext(FacesUtil.java:21)
at com.smartcall.util.SpringApplicationContextUtil.init(SpringApplicationContextUtil.java:21)
at com.smartcall.util.SpringApplicationContextUtil.<init>(SpringApplicationContextUtil.java:16)
at com.smartcall.service.impl.DbSettingsServiceImpl.init(DbSettingsServiceImpl.java:17)
at com.smartcall.service.impl.DbSettingsServiceImpl.<init>(DbSettingsServiceImpl.java:12)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100)
... 33 more
因此由于这个错误,Eclipse 中的服务器控制台报告应用程序由于先前的错误而无法启动
我的 web.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>smartcall2.0</display-name>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>
/WEB-INF/faces-config.xml,/WEB-INF/faces-managed-bean.xml,/WEB-INF/faces-navigation.xml
</param-value>
</context-param>
<listener>
<listener-class>
com.sun.faces.config.ConfigureListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>180</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
我不清楚这个错误是属于Spring还是JSF还是Eclipse。
我正在使用 Eclipse Galileo、JSF 1.2、Spring 3
请帮忙提前致谢
更新
<!-- dbSettings Service Definition -->
<bean id="dbSettingsServiceTarget"
class="com.smartcall.service.impl.DbSettingsServiceImpl">
<property name="dbSettingsDAO">
<ref local="dbSettingsDAO" />
</property>
</bean>
application-context.xml 中的这些行导致了问题。
更新
这是DbSettingsServiceImpl的代码。
public class DbSettingsServiceImpl implements DbSettingsService
{
private SpringApplicationContextUtil springApplicationContextUtil = null;
private DbSettingsDAO dbSettingsDAO;
public DbSettingsServiceImpl()
{
init();
}
public void init()
{
springApplicationContextUtil = new SpringApplicationContextUtil();
}
public DbSettingsDAO getDbSettingsDAO() {
return dbSettingsDAO;
}
public void setDbSettingsDAO(DbSettingsDAO dbSettingsDAO) {
this.dbSettingsDAO = dbSettingsDAO;
}
public String getDatabaseNameFromSettings()
{
return springApplicationContextUtil.getDatabaseDetailForThePropery("username");
}
public String getDatabasePasswordFromSettings()
{
return springApplicationContextUtil.getDatabaseDetailForThePropery("password");
}
public String getDatabaseServerNameFromSettings()
{
return springApplicationContextUtil.getDatabaseDetailForThePropery("server");
}
public String getDatabaseUserNameFromSettings()
{
return springApplicationContextUtil.getDatabaseDetailForThePropery("username");
}
}
更新
SpringApplicationContextUtil代码中的这段代码导致了问题
ServletContext servletContext = FacesUtil.getServletContext();
this.context = WebApplicationContextUtils
.getRequiredWebApplicationContext(servletContext);
当我将这段代码从构造函数移到方法时,问题就解决了。谁能预测这是为什么?
最佳答案
我的猜测是您的问题出在您的 spring 配置中:所有错误都是由 spring 框架抛出的,错误代码表明您的 ContextInitialized 事件有问题,并且您在 web.xml 中分配了一个 ContextLoadedListener。我会开始在那里寻找原因。
关于java - facescontext.getcurrentinstance 返回 nullpointerexception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4516660/
我试图通过在FacesContext类的FacesContext.getCurrentInstance()方法中调用run()来获取Runnable,但它返回null。 public class Ta
无法在自生成的线程中获得“FacesContext.getCurrentInstance()”。 需要根据后端流程动态更新组件。通过创建一个线程来监视进程并与 p:poll 一起回调组件更新来实现相同
过去几天我一直在努力处理我的网络应用程序的登录部分。我已经可以使用 tomcat 上的 JDBCRealm 成功验证用户身份(通过从 sql 服务器数据库读取用户)。现在,当用户的帐户被阻止或凭据不正
我正在创建一个基于 Spring 的 JSF 应用程序,我在其中获取返回 null 的 FacesContext.getCurrentInstance。 这是我的 Java 代码 public sta
我是否认为这可能不是最好的主意: private static Application app = FacesContext.getCurrentInstance() .getAppl
安 Id作为 Url 参数传入。我尽量确保 id是一个数字。如果没有重定向到主页 if(facilityId != null){ try{ Long.parseLong(fac
在我的应用程序中,我有一个 WebFilter。这个 Webfilter 应该检查一个 coockie。但是使用 FacesContext.getCurrentInstance() 会导致 Nullp
在我的 jsf 应用程序中,我有大量与 FacesContext 相关的静态实用程序方法。我总是问自己同样的问题? 我应该通过参数将上下文传递给方法吗?或者使用 FacesContext.getCur
我使用的对话框框架: http://www.primefaces.org/showcase-labs/ui/dialogFrameworkData.jsf 我创建了一个文件 view_test.xht
无法获得 PrimeFaces RequestContext.getCurrentInstance().openDialog()上类。我直接从 primefaces 展示中提取了示例代码,但我从来没有
我正在使用 Spring、Hibernate 和 JSF。 为了从应用程序上下文中获取 bean,我写了: public static Object findBean(String name) {
我的页面: ... ... 我的托管Bean: public class ExampleManagedBe
当 faces-config.xml 中有 3 个消息包时,会返回哪一个?我可以控制应该返回哪一个吗?当我打印出 FacesContext.getCurrentInstance().getApplic
我有一个 Facelet,它有两个 .一种形式的命令链接可以毫无问题地执行。其他形式的命令链接不起作用:a NullPointerException被抛出是因为 FacesContext.getCu
这个问题在这里已经有了答案: How do I retrieve the FacesContext within a Filter (1 个回答) 关闭 7 年前。 我有一个处理用户 session
我已经检查了其他 stackoverflow 答案,但没有一个对 JSF facescontext 有答案,所以我不得不提出一个问题。我们有 jdk 6、jsf 1.2 和 mySQL 5.5,现在我
我是一名优秀的程序员,十分优秀!