2017-12-23 18 views
1

Spring MVC에서 오류가 있습니다.[service.NewsServiceImpl] 유형의 적격 빈이 정의되지 않았습니다.

Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [service.NewsServiceImpl] is defined 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:373) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:333) 
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1088) 
at controller.Testing.main(Testing.java:24) 

NewsDAImpl 코드는 다음과 같습니다

@Repository 
public class NewsDAImpl implements NewsDA { 

@PersistenceContext 
private EntityManager context; 

@Override 
public News ... Some Other Codes 

내 NewsServiceImpl 클래스 :

@Service 
@Transactional 
public class NewsServiceImpl implements NewsService{ 

@Autowired 
private NewsDAImpl newsDa; 

@Override 
public News ... Some Other Codes 

내가 정적, 주요 무효 단지에 대한 테스트가 컨트롤러를 작성합니다.

다음
ApplicationContext context = new AnnotationConfigApplicationContext(ProjectConfig.class); 

난 그냥의 getBean 방법으로 뉴스 서비스를받을 :

NewsServiceImpl service = context.getBean(NewsServiceImpl.class); 
+0

어떻게'ProjectConfig'입니까? – ThomasEdwin

+0

구현 코드를 작성하지 마십시오. 인터페이스 코드를 작성하십시오. 따라서 인터페이스 대신 DI를 사용하십시오. – SMA

답변

2

변경

NewsServiceImpl service = context.getBean(NewsServiceImpl.class); 

NewsService service = context.getBean(NewsService.class); 

에 당신은을 가지고 있다는 점에서 은 내가 쓴 10은 @Transactional으로 주석 처리되어 있으므로 기본적으로 봄은 NewsServiceImpl 대신 NewsService을 구현하는 프록시를 만듭니다.

+1

감사합니다. 그것의 일했다. :) –