어노테이션관련 에러가 나는데 왜그러는지 모르겠습니다 ㅠ
- 작성자 :
- 강*영
- 작성일 :
- 2013-04-22 10:25:39
- 조회수 :
- 13,142
- 구분 :
- 실행환경
- 진행상태 :
- 완료
Q
제 소스입니다.
package com.amore.controller;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.amore.service.ApService;
@Controller
public class ApController {
@Inject
@Named("apService")
private ApService apService;
@RequestMapping(value="/views/ap_list.do")
public String userList1(HttpServletRequest request, HttpServletResponse response)throws Exception{
String result = apService.ApExecute(request);
if(result.equals("ok")){
System.out.println("avervice.ApExecute 성공!!");
}
return "/views/at_search.jsp";
}
}
위 소스는 컨트롤러 클래스 이구요...
특히, 빨간색 글씨부분은 주석처리하면 에러는 안납니다
아래로는 에러 메세지입니다.
Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'apController': Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.amore.service.ApService com.amore.controller.ApController.apService;
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.amore.service.ApService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.inject.Inject(), @javax.inject.Named(value=apService)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
왜그럴까요 ㅠㅠ..
package com.amore.controller;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.amore.service.ApService;
@Controller
public class ApController {
@Inject
@Named("apService")
private ApService apService;
@RequestMapping(value="/views/ap_list.do")
public String userList1(HttpServletRequest request, HttpServletResponse response)throws Exception{
String result = apService.ApExecute(request);
if(result.equals("ok")){
System.out.println("avervice.ApExecute 성공!!");
}
return "/views/at_search.jsp";
}
}
위 소스는 컨트롤러 클래스 이구요...
특히, 빨간색 글씨부분은 주석처리하면 에러는 안납니다
아래로는 에러 메세지입니다.
Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'apController': Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.amore.service.ApService com.amore.controller.ApController.apService;
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.amore.service.ApService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.inject.Inject(), @javax.inject.Named(value=apService)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
왜그럴까요 ㅠㅠ..
A
안녕하세요.. 강준영님
com.amore.service.ApService에 해당되는 클래스가 @Service나 @Component로 정의되어 있지 않아서 발생된 오류입니다..
com.amore.service.ApService 인터페이스를 구현하신 클래스(또는 인터페이스 없이 클래스로 정의) 하신 부분에 @Service("apService")로 정의하시면 되실 것 같습니다.
(빨강색 글씨 부분이 어디인지 확인 불가)
그럼.. 즐거운 하루되십시오.
감사합니다.
com.amore.service.ApService에 해당되는 클래스가 @Service나 @Component로 정의되어 있지 않아서 발생된 오류입니다..
com.amore.service.ApService 인터페이스를 구현하신 클래스(또는 인터페이스 없이 클래스로 정의) 하신 부분에 @Service("apService")로 정의하시면 되실 것 같습니다.
(빨강색 글씨 부분이 어디인지 확인 불가)
그럼.. 즐거운 하루되십시오.
감사합니다.