当前位置:编程学习 > JAVA >>

S2SH整合出错 新手实在是没有办法呀 So 发贴

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'treeManagerAction' defined in class path resource [/treeManager_spring.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.himeal.resource.action.TreeManagerAction]: Constructor threw exception; nested exception is java.lang.NullPointerException

兄弟英文不咋滴 但是一就知道是不能创建treeManagerAction 可是经过查来com.himeal.resource.action.TreeManagerAction这个路径是对的呀
我的配置如下:
<!-- 管理系统菜单 -->
<bean id="treeManagerService" class="com.himeal.resource.service.impl.TreeManagerServiceImpl">
<property name="interBiz">
<ref bean="publicBizImpl"/>
</property>
</bean>

<bean id="treeManagerAction" class="com.himeal.resource.action.TreeManagerAction">
<property name="service">
<ref bean="treeManagerService"/>
</property>
</bean>
说明:昨天晚上还能正常运行的~!可早上起来就不能了!jar包我也看了是什么我都搞了
现在我把所有的异常发上来 各路大侠们多多指点呀。


严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'treeManagerAction' defined in class path resource [/treeManager_spring.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.himeal.resource.action.TreeManagerAction]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:965)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4323)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4780)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:785)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:763)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:557)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1124)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1047)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:542)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1390)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:355)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:89)
at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:313)
at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:293)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:996)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:771)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:988)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:275)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:427)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:649)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.startup.Catalina.start(Catalina.java:585)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:415)
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.himeal.resource.action.TreeManagerAction]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:74)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:958)
... 45 more
Caused by: java.lang.NullPointerException
at org.apache.struts2.ServletActionContext.getRequest(ServletActionContext.java:112)
at com.himeal.resource.action.base.BaseAction.<init>(BaseAction.java:17)
at com.himeal.resource.action.TreeManagerAction.<init>(TreeManagerAction.java:9)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
... 47 more

  异常 s2sh 类 --------------------编程问答-------------------- 把你Action添出来啊,就这一个错误怎么看? --------------------编程问答--------------------
引用 1 楼 zcwgogo 的回复:
把你Action添出来啊,就这一个错误怎么看?



package com.himeal.resource.action;

import java.io.IOException;
import java.io.PrintWriter;

import com.himeal.resource.action.base.BaseAction;
import com.himeal.resource.service.ITreeManagerService;

public class TreeManagerAction extends BaseAction{

public ITreeManagerService service;

public String getTree(){
response.setCharacterEncoding("utf-8");
response.setContentType("text/plain");
try {
PrintWriter out = response.getWriter();
out.println(service.getSysTree(request.getContextPath()));
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

public String check(){
System.out.println("``````````````````````````````````````````````");
System.out.println(session.getAttribute("rand"));
try {
String data = request.getParameter("data");
response.setCharacterEncoding("utf-8");
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
out.println(service.check(data));
out.flush();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}


public String state(){
try {
response.setCharacterEncoding("utf-8");
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
out.println(service.state());
out.flush();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}

public ITreeManagerService getService() {
return service;
}

public void setService(ITreeManagerService service) {
this.service = service;
}

}
--------------------编程问答-------------------- 看看吧 为啥呢?这是BaseAction的
package com.himeal.resource.action.base;

import javax.servlet.ServletContext;
import javax.servlet.http.*;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class BaseAction extends ActionSupport{
public HttpServletRequest request;
public HttpSession session;
public ServletContext appliaction;
public HttpServletResponse response;

public BaseAction(){
request = ServletActionContext.getRequest();
session = request.getSession();
appliaction = session.getServletContext();
response = ServletActionContext.getResponse();
}

}
--------------------编程问答-------------------- service注入成功? --------------------编程问答-------------------- 我觉得是 定义在 BaseAction中的 response 为Null, 这个写法可以改一下, 在Action子类中获取response然后赋值给基类的response属性上去,这样就可以在本次访问中使用了。


J2EE开发技术交流----- 167765087,欢迎 --------------------编程问答--------------------
引用 4 楼 splendid_java 的回复:
service注入成功?

是否成功不知道 反正service这里没有报错! --------------------编程问答--------------------
引用 6 楼 we0476 的回复:
Quote: 引用 4 楼 splendid_java 的回复:

service注入成功?

是否成功不知道 反正service这里没有报错!
我觉得service是空的,因为你是通过注入初始化的,out.println(service.getSysTree(request.getContextPath()));这行通过了吗? --------------------编程问答--------------------
引用 7 楼 splendid_java 的回复:
Quote: 引用 6 楼 we0476 的回复:

Quote: 引用 4 楼 splendid_java 的回复:

service注入成功?

是否成功不知道 反正service这里没有报错!
我觉得service是空的,因为你是通过注入初始化的,out.println(service.getSysTree(request.getContextPath()));这行通过了吗?

这个(out.println(service.getSysTree(request.getContextPath()));)应该写在那里? --------------------编程问答--------------------
引用 8 楼 we0476 的回复:
Quote: 引用 7 楼 splendid_java 的回复:

Quote: 引用 6 楼 we0476 的回复:

Quote: 引用 4 楼 splendid_java 的回复:

service注入成功?

是否成功不知道 反正service这里没有报错!
我觉得service是空的,因为你是通过注入初始化的,out.println(service.getSysTree(request.getContextPath()));这行通过了吗?

这个(out.println(service.getSysTree(request.getContextPath()));)应该写在那里?

晕~! 这是今天报的错 以前是可以通过的! --------------------编程问答--------------------
引用 8 楼 we0476 的回复:
Quote: 引用 7 楼 splendid_java 的回复:

Quote: 引用 6 楼 we0476 的回复:

Quote: 引用 4 楼 splendid_java 的回复:

service注入成功?

是否成功不知道 反正service这里没有报错!
我觉得service是空的,因为你是通过注入初始化的,out.println(service.getSysTree(request.getContextPath()));这行通过了吗?

这个(out.println(service.getSysTree(request.getContextPath()));)应该写在那里?
你测试一下,在这行前面log一下service,看看是否是null --------------------编程问答--------------------
引用 10 楼 splendid_java 的回复:
Quote: 引用 8 楼 we0476 的回复:

Quote: 引用 7 楼 splendid_java 的回复:

Quote: 引用 6 楼 we0476 的回复:

Quote: 引用 4 楼 splendid_java 的回复:

service注入成功?

是否成功不知道 反正service这里没有报错!
我觉得service是空的,因为你是通过注入初始化的,out.println(service.getSysTree(request.getContextPath()));这行通过了吗?

这个(out.println(service.getSysTree(request.getContextPath()));)应该写在那里?
你测试一下,在这行前面log一下service,看看是否是null

你的意思是service跟本没有注入进去? --------------------编程问答-------------------- 你把先把继承去掉,直接继承 ActionSupport 试试。我没你这样写过:
request = ServletActionContext.getRequest();
 session = request.getSession();
 appliaction = session.getServletContext();
 response = ServletActionContext.getResponse();

但是这个是在Action是在容器初始化的时候就初始化的,你这几句就表面上看是肯定有问题的,应该初始化容易哪里来的session和request这些。 我没试过你这种写法,你看看是不是我说的这个问题。 --------------------编程问答-------------------- service 注入好像有问题,都没启动起来,是注入失败了!建议 Lz 起变量名时注意点。再仔细看看应该就找出问题了! --------------------编程问答-------------------- 如果你是昨晚还是好的现在不行了,我有个想法那就是你的目录里有两个ssh项目.当有两个时有时候会发生包的冲突.你可以检查一下你的tomcat目录
--------------------编程问答--------------------
引用 13 楼 Iamagril 的回复:
service 注入好像有问题,都没启动起来,是注入失败了!建议 Lz 起变量名时注意点。再仔细看看应该就找出问题了!


Constructor threw exception; nested exception is java.lang.NullPointerException
这句都不仔细看?service注入失败时会报空指针么?

service 就算报空指针也是在运行时 --------------------编程问答--------------------
引用 12 楼 zcwgogo 的回复:
你把先把继承去掉,直接继承 ActionSupport 试试。我没你这样写过:
request = ServletActionContext.getRequest();
 session = request.getSession();
 appliaction = session.getServletContext();
 response = ServletActionContext.getResponse();

但是这个是在Action是在容器初始化的时候就初始化的,你这几句就表面上看是肯定有问题的,应该初始化容易哪里来的session和request这些。 我没试过你这种写法,你看看是不是我说的这个问题。


对 没错 我反BaseAction里的默认构造去掉就可以了 让子类去干活吧。谢谢你
补充:Java ,  Java EE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,