springmvc 中 Instantiation of bean failed实例化Bean失败错误

配置springMVC 项目时,启动tomcat服务器报错:

错误:

信息: Initializing Spring FrameworkServlet ‘springmvc‘

2015-8-19 9:57:35 org.apache.catalina.core.ApplicationContext log

严重: StandardWrapper.Throwable

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userController‘ defined in file [C:\tomcat7.059\webapps\spring818\WEB-INF\classes\com\controller\UserController.class]: Instantiation of bean
failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.controller.UserController]: Constructor threw exception; nested exception is java.lang.ExceptionInInitializerError

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.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)

at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)

at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)

at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)

at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)

at javax.servlet.GenericServlet.init(GenericServlet.java:158)

at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284)

at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197)

at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)

at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5262)

at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5550)

at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)

at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)

at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)

at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1245)

at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1895)

at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)

at java.util.concurrent.FutureTask.run(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.controller.UserController]: Constructor threw exception; nested exception is java.lang.ExceptionInInitializerError

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)

... 33 more

Caused by: java.lang.ExceptionInInitializerError

at com.dao.Impl.UserDaoImpl.<init>(UserDaoImpl.java:14)

at service.impl.UserServiceImpl.<init>(UserServiceImpl.java:20)

at com.controller.UserController.<init>(UserController.java:29)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)

... 35 more

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userController‘ defined in file [C:\tomcat7.059\webapps\spring818\WEB-INF\classes\com\controller\UserController.class]: Instantiation of bean failed; nested exception
is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.controller.UserController]: 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.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)

at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)

at com.utils.SpringUtil.<clinit>(SpringUtil.java:16)

... 43 more

Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.controller.UserController]: 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)

... 56 more

Caused by: java.lang.NullPointerException

at com.utils.SpringUtil.getBean(SpringUtil.java:21)

at com.dao.Impl.UserDaoImpl.<init>(UserDaoImpl.java:14)

at service.impl.UserServiceImpl.<init>(UserServiceImpl.java:20)

at com.controller.UserController.<init>(UserController.java:29)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newIn

stance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)

... 58 more

2015-8-19 9:57:35 org.apache.catalina.core.StandardContext loadOnStartup

严重: Servlet [springmvc] in web application [/spring818] threw load() exception

java.lang.NullPointerException

at com.utils.SpringUtil.getBean(SpringUtil.java:21)

at com.dao.Impl.UserDaoImpl.<init>(UserDaoImpl.java:14)

at service.impl.UserServiceImpl.<init>(UserServiceImpl.java:20)

at com.controller.UserController.<init>(UserController.java:29)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)

at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:74)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:958)

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.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)

at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)

at com.utils.SpringUtil.<clinit>(SpringUtil.java:16)

at com.dao.Impl.UserDaoImpl.<init>(UserDaoImpl.java:14)

at service.impl.UserServiceImpl.<init>(UserServiceImpl.java:20)

at com.controller.UserController.<init>(UserController.java:29)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)

at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:74)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:958)

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.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)

at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)

at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)

at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)

at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)

at javax.servlet.GenericServlet.init(GenericServlet.java:158)

at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284)

at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197)

at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)

at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5262)

at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5550)

at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)

at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)

at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)

at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1245)

at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1895)

at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)

at java.util.concurrent.FutureTask.run(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

2015-8-19 9:57:35 org.apache.catalina.startup.HostConfig deployDirectory

(每个人出现的错误不一样,解决的方式也不一样)

出现实例化bean失败的错误,一般都是想到spring-bean等子类的jar包有没有导入或是spring.xml配置文件是不是出错,

我一开始就是沿着这两条线去处理,换了正确工程的jar和xml配置文件可问题依然存在,

可dao和service的类经过单元测试都有效,那只能出现在controller层的类了,所以就排查UserController类,

类如下:

@Controller

@RequestMapping("/user")

public class UserController {

private UserServiceImpl service = new UserServiceImpl();

@RequestMapping("/queryAllInfo")

@ResponseBody

public Map<String,Object> queryAllInfo(HttpServletRequest request,HttpServletResponse response)

{

ResultUtil result =new ResultUtil();

List<Map<String,Object>> list = service.queryAllInfo();

if(list.size()>0)

{

result.setRows(list);

result.setMsg("查询成功!");

}else

{

result.setSuccess(false);

result.setMsg("删除失败!");

}

return result.getResult();

}

}

当把 private UserServiceImpl service = new UserServiceImpl(); 这个类的实例化语句(UserServiceImpl service = new UserServiceImpl())放到方法中后重启服务器

就没有报错了。因为之前用struts以及daoImpl和serviceImpl 都是直接在在类成员变量声明时直接进行实例化,所以养成了这个习惯,以为在springmvc中也可以,

真是坏的习惯害死人呀

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-12-28 00:46:24

springmvc 中 Instantiation of bean failed实例化Bean失败错误的相关文章

asp.net 导出word格式的数据,检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件时失败 错误: 80070005

asp.net 导出word格式的数据,检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件时失败 错误: 80070005 以下是该问题修改方案: 一.在 计算机——> 控制面板——> 管理工具——> 组件服务 下(或者 开始——>运行 ——>dcomcnfg.exe ) 二. 计算机——> 我的电脑——>DCOM配置 找到Microsoft Word  文档(该名称不同的机器有可能不同)

Spring实例化bean的三种方式

在面向对象编程的过程中,要想调用某个类的成员方法,首先要实例化该类的成员变量. 在Spring 中,实例化Bean有三种方式: 1.构造器实例化:2.静态工厂方式实例化:3.实例化工厂方式实例化 构造器实例化:Spring容器通过Bean对应的类中默认的构造器函数实例化Bean. 1-1.创建一个实体类 Person1 package com.mengma.instance.constructor; public class Person1 { } 1-2.创建Spring配置文件,在 com.

SpringMVC 源代码深度解析 IOC容器(Bean实例化和依赖注入)

SpringMVC最核心的IOC的控制反转,动态的向某个对象提供它所需要的其他对象,例如:对象A时,需要对象B时,这时不像以前我们之前要在A对象里实例化B对象,这时B对象的实例化由IOC容器会主动创建一个对象B然后注入到对象A里,提供使用.我们项目开发中,最经常用到,那怎么实现实例Bean并依赖注入呢?我们今天带着这些问题来通过SpringMVC源代码进行深入的解析.这篇介绍不对注解实例化和注入进行讲解,这个放在后面在介绍. 我们平常写的一个类,并依赖调用了类的某个方法,这时需要依赖那个类已经实

spring quartz:Instantiation of bean failed; nested exception is java.lang.IncompatibleClassChangeErr

spring 调度类初始化失败,分析是jar包冲突,日志如下: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scheduler' defined in file [D:\InstallApplication\apache-tomcat-7.0.23\wtpwebapps\campaign\WEB-INF\classes\spring\applicationConte

SpringMVC中出现&quot; 400 Bad Request &quot;错误(用@ResponseBody处理ajax传过来的json数据转成bean)的解决方法

最近angularjs post到后台 400一头雾水 没有任何错误. 最后发现好文,感谢作者 SpringMVC中出现" 400 Bad Request "错误(用@ResponseBody处理ajax传过来的json数据转成bean)的解决方法 今天开发过程中,在SpringMVC中的Action中处理前台ajax请求传过来的json数据直接转成对应的实体类时出错:400 Bad Request,后台也不报错,400指的的是请求无效(请求有语法问题或者不能满足请求),调试了好长时间

Spring MVC集成thymeleaf时提示:defined in ServletContext resource [/WEB-INF/SrpingMVCTest-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException

错误提示: defined in ServletContext resource [/WEB-INF/SrpingMVCTest-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.thymeleaf.templateresolver.ServletContex

SpringMVC中实现Bean Validation(JSR 303 JSR 349 JSR 380)

JSR 303是针对bean数据校验提出的一个规范.使用注解方式实现数据校验. 每个注解的用法这里就不多介绍,请移步JSR 303 - Bean Validation 介绍及最佳实践 笔者上面提到的JSR303是专家组成员向JCP提交的第一版Bean Validation, 主流Bean Validation使用Hibernate的实现,本文使用hibernate-validator 各个版本的规范对应关系如下: JSR 380 (Bean Validation 2.0) JSR 349 (Be

Spring中bean的实例化过程

1.从缓存中.优先从一级缓存中拿,有则返回. 如果没有,则从二级缓存中获取,有则返回. 如果二级缓存中拿不到,则从三级缓存中拿,能拿到,则从三级缓存中删除,移到二级缓存. 如果三级缓存也没有,则返回null. 2. 如果是单例模式, 则走createBean 的流程,进行bean对象的实例化. 2.1 获取到该beanDefinition对应的字节码对象. 2.2 prepareMethodOverrides. 检查beanDefinition对象的每一个methodOverride的对象.如果

Spring源码解析(四)Bean的实例化和依赖注入

我们虽然获得了Bean的描述信息BeanDefinition,但是什么时候才会真正的实例化这些Bean呢.其实一共有两个触发点,但是最后实际上调用的是同一个方法. 第一个:在AbstractApplicationContext的refresh()方法中,容器会初始化lazy-init=false的bean. // Instantiate all remaining (non-lazy-init) singletons. finishBeanFactoryInitialization(beanFa