2014-05-11 3 views
1

circle 클래스의 응용 프로그램 컨텍스트를 사용하여 bean을 만들려고 할 때 다음 오류가 발생합니다! Circle 클래스는 draw() 메서드를 포함하는 Shape 인터페이스를 구현합니다.bean 작성 중 오류 : bean 인스턴스화에 실패했습니다. 중첩 예외는 java.lang.ExceptionInInitializerError입니다.

구성 : 필요한 모든 항아리 (봄과 아파치 평민 로깅)와 이클립스

내가 배우고 봄이 설치 자바 프로젝트. 내 classpath 내 src 폴더에 spring.xml이 있습니다. 또한 최신 jar (4.0.4 릴리스와 함께 작업 한 Spring 4.0.4)를 다운로드했지만 현재 작동하지 않습니다. 이 문제를 해결할 수있는 해결책은 없을 것입니다.

오류 :

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 - 자바 독
스프링 AOP-4.0.4.RELEASE - 소스
스프링 양태-4.0.4.RELEASE
스프링 양태-4.0.4.RELEASE-자바 독
스프링 양태-4.0.4 . 릴리즈 - 소스
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-자바 독
스프링 상황 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 리스 자바 독
스프링 코어 4.0.4.RELEASE - 소스
스프링 발현 4.0.4.RELEASE
스프링 발현 4.0.4.RELEASE-자바 독
스프링 발현 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-소스
스프링 악기 바람둥이-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-자바 독
스프링 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-자바 독
스프링 OXM-4.0.4.RELEASE - 소스
스프링 테스트 4.0.4.RELEASE
스프링 테스트 4.0.4.RELEASE-자바 독
스프링 테스트 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-포틀릿 4.0.4.RELEASE
스프링 webmvc-포틀릿 4.0.4.RELEASE-자바 독
스프링 webmvc 포틀릿-4.0. 4. 릴리스 - 소스
spring-websocket-4.0.4.RELEASE
spring-websocket-4.0.4.RELEASE-javadoc
spring-websoc ket-4.0.4.RELEASE-sources

이 외에 다른 기본 시스템 라이브러리가 모두 참조됩니다.

PropertyEditorRegistrySupport.class.getClassLoader() 

null 때문에

+0

stacktrace 맨 아래부터 시작하십시오. 더 이상 포함하지 않는 한 NullPointerException이 표시됩니다. – Jason

+0

실제 문제는 org.springframework.beans.PropertyEditorRegistrySupport에서 NPE가 발생했습니다. '; 즉이 클래스의 정적 이니셜 라이저. 어딘가 잘못 설정 되었습니까? 문제는 해당 NPE와 관련된 메시지가 없으므로 그곳에서 일어나는 일을 말하기 어렵다는 것입니다. – fge

+0

클래스 패스에는 어떤 병이 있습니까? 목록을 올리세요. –

답변

4

문제가 발생합니다.클래스 PropertyEditorRegistrySupport 대신 시스템 클래스 로더의 부트 스트랩 클래스 로더에 의해로드 된 경우의 JavaDoc에 따르면,이 상황이 발생합니다

Some implementations may use null to represent the bootstrap class loader. This method will return null in such implementations if this class was loaded by the bootstrap class loader.

아마도 당신의 봄 라이브러리가 승인 클래스 경로에있는?

+0

예 모든 나의 Spring 라이브러리가 클래스 패스에있다. 부트 스트랩 클래스 로더와 시스템 로더에 대해 좀 더 자세히 설명해 주시겠습니까? Eclipse에서 작성한 클래스 경로 파일은 다음과 같습니다. \t \t \t \t user3626602

+0

고맙습니다. 해결책을 찾았습니다. Eclipse에서 라이브러리를 추가 할 때 부트 스트랩 클래스 로더에 사용자 라이브러리를 추가하는 옵션이 있는지 묻습니다. 확인란을 선택 취소하고 코드가 완벽하게 실행됩니다. 힌트를 가져 주셔서 감사합니다! – user3626602

+1

다행히 도움이되었습니다. 그럼에도 불구하고 나는이 사건을 기꺼이 고려할 의향이 있는지 봄에 문제를 제기했다 : https://jira.spring.io/browse/SPR-11780 –

관련 문제