2013-01-10 6 views
1
<bean name="readerService" class="com.mayank.example1.ReaderService"/> 
    <property name="reader" ref="fileReader" /> 
</bean> 
<bean name="fileReader" class="com.mayank.example1.FileReader"> 
    <constructor-arg value="resources/myfile.txt" /> 
</bean> 

생성자에서 인수를 인자로 취합니다. 리더는 인터페이스입니다. XML 문서에 행 15 : 스레드 "주요"org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException에스프링 속성 참조가 작동하지 않습니다.

예외 : 을 FileReader 그것은 재산 리더를 복용하고 예외를 throw되지 봄 리더에게

를 구현하는 클래스입니다 클래스 경로 자원 [reader-beans.xml]에서 유효하지 않습니다. 중첩 예외는 org.xml.sax.SAXParseException : cvc-complex-type.2.4.a : 요소 'property'로 시작하는 잘못된 내용이 발견되었습니다. '{ "http://www.springframework.org/schema/beans":import,"http://www.springframework.org/schema/beans":alias "http://www.springframework.org/schema/beans ": bean, WC [## other :"http://www.springframework.org/schema/beans "]} '예상 됨

+1

당신은 전체 XML을 게시 할 수 있습니까? – ThanksForAllTheFish

+2

<- 빈 태그를 너무 일찍 닫고 있습니까? – esaj

+0

STS를 사용하고 있습니까? –

답변

2

필수 xml 네임 스페이스 beancontext이 있는지 확인하십시오. 구성 파일의 맨 위에. 내 예제는 사용중인 Spring 버전을 조정해야 할 수도있는 Spring 버전 3.1을 사용합니다.

readerService bean 태그가 너무 일찍 닫히는 조정에 주목하십시오. 당신이 너무 일찍 빈 태그 닫는 것 같습니다

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:context="http://www.springframework.org/schema/context" 
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> 

<bean name="readerService" class="com.mayank.example1.ReaderService"> 
    <property name="reader" ref="fileReader" /> 
</bean> 
<bean name="fileReader" class="com.mayank.example1.FileReader"> 
    <constructor-arg value="resources/myfile.txt" /> 
</bean> 

</beans> 
+0

답변에 대한 thatnks는 실제로 getter가 있지만 setter가없는 클래스 파일과 관련되어 있습니다. – Innovation

3

(마지막에 />주의를, 이것은 단지 > 안?) :

<bean name="readerService" class="com.mayank.example1.ReaderService"/> 
    <property name="reader" ref="fileReader" /> 
</bean> 
관련 문제