2015-01-30 2 views
0

내가 수행하고있는 것 : 스프링 애플리케이션 외부 JAR을 다른 비 스프링 애플리케이션에로드하고있다. 나는 이런 식으로 일을 해요 :이 내가받은 예외스프링 컨텍스트를 올바르게로드 할 수 없음

ApplicationContext ap = new ClassPathXmlApplicationContext("classpath:/META-INF/spring/application-context.xml"); 
MyService myService = (MyService) ap.getBean("myBusinessService"); 

:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myBusinessService': Injection of autowired dependencies failed; nested exception is 
org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.test.domain.dao.MyDAO com.test.domain.service.impl.MyBusinessService.viaggioDAO; nested exception is 
org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.test.domain.dao.MyDAO] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. 

패키지를 그 항아리 안에 것은 다음과 같습니다

  • com.test.domain.service 서비스 용 인터페이스
  • com.test.domain.services.impl f DAO 구현을위한 DAO 인터페이스 또는 서비스 구현
  • com.test.domain.dao
  • com.test.domain.dao.impl

질문 : 왜이를 수신하고 오류?

편집 : 내 앱에 대한 추가 정보

응용 프로그램의 context.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" 
     xmlns:mvc="http://www.springframework.org/schema/mvc" 
     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 
          http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 

    <!-- Spring IoC Context --> 
    <context:component-scan base-package="com.test" /> 

    <import resource="root-config.xml" /> 
    <import resource="classpath:/root-context.xml" /> 

    <!-- Enables the Spring MVC @Controller programming model --> 
    <mvc:annotation-driven /> 

</beans> 

MyBusinessService.java

@Service(value="myBusinessService") 
public class MyBusinessService implements MyService { 
    @Autowired 
    private MyDAO myDAO; 

    @Override 
    public List<Stuff> getAllStuff() throws SQLException { 
     List<Stuff> stuff = this.myDAO.findAllStuff(); 
     return stuff; 
    } 
} 
+0

'@ Repository' 어노테이션이 DAO 인터페이스 또는 DAO 구현에 주어 졌는지 알려주십시오. – Mithun

+0

DAO 구현에서 제공됩니다. 그리고 서비스 하나도 서비스 구현에 있습니다. – abierto

+0

@abierto 당신은 우리와 함께 application-context.xml과 com.test.domain.service.impl.MyBusinessService.java 클래스를 공유 할 수 있습니까? – erhun

답변

0

가시성 문제, 당신이 당신의 dispatcher-servlet.xml의 모든 패키지를 나열했습니다 여부를 확인합니다. 당신은을 사용하는 경우 @Component 또는 @Service

<context:component-scan base-package="com.test.domain" /> 

은 운영자 또한

을 확인 볼 수있는 모든 패키지를 만들기 위해, 추가, 당신이 autowire하기 위해 노력하는 빈은 유효한 규정이 갈까요 xml 구성을 확인하십시오. 디스패처에서 bean을 정의하십시오. autowiring하기 전에

+0

내 스프링 용기는 웹 응용 프로그램이 아니지만 새로운 응용 프로그램은 cointainer (즉, 바람둥이) 내에서 실행됩니다. 모든 서비스와 daos에는 서비스 또는 저장소 관련 서비스 주석이 있습니다. 심지어 구성 요소 스캔 내 XML에 이루어집니다.당신이 "autowiring 전에 dispatcher에서 bean을 정의하는 것"은 무엇을 의미합니까? – abierto