当我尝试使用应用程序上下文为该圆类创建bean时,我正面临以下错误! Circle类实现包含方法draw()的Shape接口。创建bean时出错:bean实例化失败;嵌套的异常是java.lang.ExceptionInInitializerError
配置:
我学习春天和已经建立了Java项目在Eclipse中所有需要的jar(Spring和Apache通用日志)。我在src文件夹的classpath中有spring.xml。也尝试下载最新的jar(Spring 4.0.4发布版,以前使用4.0.0),但现在不起作用。想不到任何解决方案来解决这个问题。
错误:
May 11, 2014 6:20:50 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org[email protected]90832e: startup date [Sun May 11 18:20:50 EDT 2014]; root of context hierarchy
May 11, 2014 6:20:50 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [spring.xml]
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor': Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1076)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1021)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:88)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
at com.springApplication.DrawingApplication.main(DrawingApplication.java:16)
Caused by: java.lang.ExceptionInInitializerError
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1071)
... 13 more
Caused by: java.lang.NullPointerException
at org.springframework.beans.PropertyEditorRegistrySupport.(PropertyEditorRegistrySupport.java:92)
... 14 more
DrawingApplication.java
package com.springApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class DrawingApplication {
public static void main(String[] args) {
//The beanFactory reads from an XML file
//BeanFactory context = new XmlBeanFactory(new FileSystemResource("spring.xml"));
//Application Context provides -- Event notification and more than Bean Factory
ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
//Here we pass the id of the bean from the XML given in the above line
Shape shape = (Shape)context.getBean("circle");
//Calling the draw method through object local object created using Spring
shape.draw();
}
}
Circle.java
package com.springApplication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
public class Circle implements Shape{
private Point center;
public Point getCenter() {
return center;
}
@Autowired
@Qualifier("circleRelated")
public void setCenter(Point center) {
this.center = center;
}
@Override
public void draw() {
System.out.println("Drawing a Circle");
System.out.println("Center Point is: (" + center.getX() + ", " + center.getY() + ")");
}
}
Point.java
package com.springApplication;
public class Point {
private int x;
private int y;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
spring.xml
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
请让我知道是否有其他需要。有人请帮忙!
抱歉关于错误的放置!
@Andrei斯特凡罐的
名单---------
共享记录-1.1.3
弹簧AOP-4.0.4.RELEASE
弹簧AOP-4.0.4 .RELEASE-的Javadoc
弹簧AOP-4.0.4.RELEASE来源
弹簧方面-4.0.4.RELEASE
弹簧方面-4.0.4.RELEASE-的Javadoc
弹簧方面-4.0.4 .RELEASE-sources
spring-beans-4.0.4.RELEASE
弹簧豆-4.0.4.RELEASE-的Javadoc
弹簧豆-4.0.4.RELEASE来源
弹簧积聚SRC-4.0.4.RELEASE
弹簧上下文4.0.4.RELEASE
弹簧上下文4.0.4.RELEASE-的Javadoc
弹簧上下文4.0.4.RELEASE来源
弹簧上下文支撑4.0.4.RELEASE
弹簧上下文支持-4.0.4。 RELEASE-javadoc
spring-context-support-4.0.4.RELEASE-sources
spring-core-4.0.4.RELEASE
spring-core-4.0.4.RE租赁的Javadoc
弹簧芯4.0.4.RELEASE来源
弹簧表达-4.0.4.RELEASE
弹簧表达-4.0.4.RELEASE-的Javadoc
弹簧表达-4.0.4。RELEASE-源
弹簧框架-BOM-4.0.4.RELEASE
弹簧框架-BOM-4.0.4.RELEASE-的Javadoc
弹簧框架-BOM-4.0.4.RELEASE来源
弹簧仪器4.0.4.RELEASE
弹簧仪器4.0.4.RELEASE-的Javadoc
弹簧仪器4.0.4.RELEASE来源
弹簧仪器Tomcat的4.0.4.RELEASE
弹簧instrument-tomcat-4.0.4.RELEASE-javadoc
spring-instrument-tomcat-4.0.4.RELEASE-sources
spring-j DBC-4.0.4.RELEASE
弹簧JDBC-4.0.4.RELEASE-的Javadoc
弹簧JDBC-4.0.4.RELEASE来源
弹簧JMS-4.0.4.RELEASE
弹簧JMS- 4.0.4.RELEASE-的Javadoc
弹簧JMS-4.0.4.RELEASE来源
弹簧消息传递4.0.4.RELEASE
弹簧消息传递4.0.4.RELEASE-的Javadoc
弹簧messaging- 4.0.4.RELEASE-sources
spring-orm-4.0.4.RELEASE
spring-orm-4.0.4.RELEASE -javadoc
弹簧ORM-4.0.4.RELEASE来源
弹簧OXM-4.0.4.RELEASE
弹簧OXM-4.0.4.RELEASE-的Javadoc
弹簧OXM-4.0.4.RELEASE来源
弹簧 - 测试 - 4.0.4.RELEASE
弹簧 - 测试 - 4.0.4.RELEASE-的Javadoc
弹簧 - 测试 - 4.0.4.RELEASE来源
弹簧-TX-4.0.4.RELEASE
弹簧-tx-4.0.4.RELEASE-javadoc
spring-tx-4.0.4.RELEASE-sources
spring-web-4.0.4.RELEASE
弹簧网络4.0.4.RELEASE-的Javadoc
弹簧网络4.0.4.RELEASE来源
弹簧webmvc-4.0.4.RELEASE
弹簧webmvc-4.0.4.RELEASE-的Javadoc
弹簧webmvc-4.0.4.RELEASE来源
弹簧webmvc的portlet-4.0.4.RELEASE
弹簧webmvc的portlet-4.0.4.RELEASE-的Javadoc
弹簧webmvc的portlet-4.0。 4.RELEASE来源
spring-websocket-4.0.4.RELEASE
spring-websocket-4.0.4.RELEASE-javadoc
spring-websoc ket-4.0.4.RELEASE-sources
所有这些加上其他默认系统库都被引用。发生
+0
从stacktrace的底部开始 - 我在那里看到一个NullPointerException(除非有更多的你没有包含)。 –
+0
真正的问题是在org.springframework.beans.PropertyEditorRegistrySupport中抛出的NPE。 ';即在这个类的静态初始化器中。配置错误?问题是没有与该NPE相关的消息,因此很难说出那里发生了什么。 –
+0
你在classpath中有什么罐子?请张贴清单。 –