當我嘗試使用應用程序上下文爲該圓類創建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.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(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.<clinit>(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
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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">
<bean id="pointA" class="com.springApplication.Point">
<qualifier value="circleRelated" />
<property name="x" value="0"/>
<property name="y" value="0"/>
</bean>
<bean id="PointB" class="com.springApplication.Point">
<property name="x" value="0"/>
<property name="y" value="20"/>
</bean>
<bean id="PointC" class="com.springApplication.Point">
<property name="x" value="-20"/>
<property name="y" value="0"/>
</bean>
<bean id="circle" class="com.springApplication.Circle">
</bean>
<!-- <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" /> -->
<context:annotation-config/>
</beans>
請讓我知道是否有其他需要。有人請幫忙!
抱歉關於錯誤的放置!
@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
所有這些加上其他默認系統庫都被引用。發生
從stacktrace的底部開始 - 我在那裏看到一個NullPointerException(除非有更多的你沒有包含)。 – Jason
真正的問題是在org.springframework.beans.PropertyEditorRegistrySupport中拋出的NPE。';即在這個類的靜態初始化器中。配置錯誤?問題是沒有與該NPE相關的消息,因此很難說出那裏發生了什麼。 –
fge
你在classpath中有什麼罐子?請張貼清單。 –