当我尝试使用循环类的Application Context创建bean时,我面临以下错误!Circle类实现了Shape
接口,其中包含一个方法绘制()
。
配置:
我正在学习Spring,并在eclipse中设置了一个Java项目,其中包含所有必需的jar(Spring和Apache公共日志记录)。我在src文件夹的类路径中有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.springframework.context.support.ClassPathXmlApplicationContext@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() + ")");
}
}
点.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 Stefan
Jars ---------
Commons-loging-1.1.3
spring-expression-4.0.4.RELEASE
spring-expression-4.0.4.RELEASE-javadoc
spring-framework-bom-4.0.4.RELEASE-源
spring-framework-bom-4.0.4.RELEASE
spring-framework-bom-4.0.4.RELEASE-javadoc
spring-instrument-4.0.4.RELEASE-源
spring-instrument-4.0.4.RELEASE
spring-instrument-4.0.4.RELEASE-javadoc
spring-instrument-tomcat-4.0.4.RELEASE-源
spring-instrument-tomcat-4.0.4.RELEASE
spring-context-4.0.4.RELEASE
spring-context-4.0.4.RELEASE-javadoc
spring-context-4.0.4.RELEASE-源
spring-context-support-4.0.4.RELEASE
spring-context-support-4.0.4.RELEASE-javadoc
spring-context-support-4.0.4.RELEASE-源
spring-core-4.0.4.RELEASE
spring-core-4.0.4.RELEASE-javadoc
spring-core-4.0.4.RELEASE-源
spring-expression-4.0.4.RELEASE
spring-aop-4.0.4.RELEASE-javadoc
spring-aop-4.0.4.RELEASE-源
spring-aop-4.0.4.RELEASE
spring-aspects-4.0.4.RELEASE-javadoc
spring-aspects-4.0.4.RELEASE-源
spring-aspects-4.0.4.RELEASE
spring-beans-4.0.4.RELEASE-javadoc
spring-beans-4.0.4.RELEASE
spring-beans-4.0.4.RELEASE
spring-build-src-4.0.4.RELEASE-javadoc
spring-jms-4.0.4。RELEASE-javadoc
spring-jms-4.0.4。RELEASE
spring-Message-4.0.4。RELEASE-javadoc
spring-Message-4.0.4。RELEASE-源
spring-orm-4.0.4。RELEASE
spring-orm-4.0.4。RELEASE-javadoc
spring-orm-4.0.4。RELEASE-源
spring-oxm-4.0.4。RELEASE
spring-oxm-4.0.4。RELEASE-源
spring-test-4.0.4。RELEASE
spring-test-4.0.4。RELEASE
Spring测试。RELERELEASE-javadoc
spring-web-4.0.4。RELEASE-源
spring-webmvc-4.0.4。RELEASE
spring-webmvc-4.0.4。RELEASE-源
spring-webmvc-portlet-4.0.4。RELEASE
spring-webmvc-portlet-4.0.4。RELEASE-javadoc
spring-webmvc-portlet-4.0.4。RELEASE-源
spring-webock-4.0.4。RELEASE
spring-webock-4.0.4。RELEASE
spring-webock-4.0.4。释放源
所有这些加上其他默认的系统库都被引用。
出现此问题的原因是
PropertyEditorRegistrySupport.class.getClassLoader()
isnull
。根据JavaDoc,如果类属性编辑注册支持
已由引导类加载器而不是系统类加载器加载,则会发生这种情况:
一些实现可能使用null来表示引导类加载器。如果此类由引导类加载器加载,则此方法将在此类实现中返回null。
也许您的Spring库在认可的类路径上?
下面是我的文件: bean初始化失败 更多跟踪: 原因:org.springframework.beans.factory.unsatisfiedDependencyException:创建类路径资源[org/springframework/boot/autocconfigure/session/sessionrepositoryfilterconfiguration.class]中定义的名为“s
我开始使用spring,我正在尝试使用Security、Hibernate和ThymLeaf构建一个应用程序。 我犯了一个让我困了好几天的错误。 以下是日志: application.java WebSecurityConfig.java 我的UserController spring.properties: DatabaseConfig.java 和MvcConfig: 下面是我的项目结构: 如
完全错误: BeanCreationException:创建名为“Transaction ManagerPostProcessor”的bean时出错:bean初始化失败;嵌套异常是org.springframework.beans.factory.beanCreationException:创建名为“事务管理器”的bean时出错:在设置bean属性“会话工厂”时无法解析对bean“会话工厂”的引用
问题内容: 我有一个使用Spring MVC,Spring Security和Spring Data的Spring应用程序。一切都用来工作完美,直到我从更新的春天数据的版本来。 这是无法创建的存储库bean(BeanCreationException): 这是(Maven): 堆栈跟踪: 如果还有其他与此问题相关的信息,请告诉我,我将更新问题。 问题答案: 这是由于您配置的Spring Frame
我试图让公共资源日志为log4j配置工作,但是当启动服务器时,我总是得到一个异常。当试图使用StringUtils时,我也会得到一个类似的异常,它可以通过另一个公共资源库获得。 pom依赖项:
下面是我的applicationContext.xml的外观: ………… 我得到了这个错误: 创建异常:创建名称为“自定义编辑器配置器”的 Bean 时出错:在 Servlet上下文资源 [/WEB-INF/Spring-servlet.xml]中定义名称的 Bean 时出错: 初始化 Bean 失败;嵌套的异常是组织.Spring框架.豆.类型不匹配异常: 无法将类型为 “java.util.L