spring프로젝트_0905
No mapping found for HTTP request with URI 에러로 appservlet 못불러오는 에러
> servlet context.xml 에 context component scan 태그로 controller bean 등록이 안되어있었음
<context:component-scan base-package="컨트롤러 경로"/>
serviceImpl class 에서 @Log4j import 안되는 오류 (maven dependencies에 log4j가 비활성화 되어 있음)
> pom.xml 의 log4j dependency 부분의 scope가 runtime으로 되어있는 태그 주석하여 빌드시에도 동작하도록 수정
--------------------------------------------------------------------------------
mapper > service 테스트 완료 후 controller 테스트 진행 중
** @controller 와 @restController 차이
controller (controller로 view 반환할 때) :: Controller는 요청을 처리한 후에 ViewName을 반환
> DispatcherServlet은 ViewResolver를 통해 ViewName에 해당하는 View를 찾아 사용자에게 반환
restController (controller로 데이터 반환해야 할 때) :: 반환되는 객체는 Json으로 Serialize되어 사용자에게 반환
> 컨트롤러에서는 데이터를 반환하기 위해 @ResponseBody 어노테이션을 활용해주어야 함
----------------------------------------------------------------------------------------------------------------------------------------------------------------
프로젝트 구동 순서
web.xml > web.xml 상단의 context listener 태그의 context loader 등록 > web.xml 의 context-param으로 등록된 root-context.xml 파일 스캔 > root-context.xml에 있는 빈 설정 동작 > root-context.xml에 정의 된 객체(bean)들은 스프링 영역(context)안에 생성되고 의존성 처리
의존성 처리 이후, spring mvc에서 사용하는 dispatcherServlet 클래스가 웹관련 처리를 위해 servlet-context.xml 파일을 로딩하고 해석함 > 이 과정에서 등록된 객체 bean들은 기존에 만들어진 객체들과 같이 연동됨 > root-context.xml에서 정의된 bean들과 servlet-context.xml에서 정의된 bean들이 연동됨
https://lifere.tistory.com/120 (프로젝트 구동 프로세스 참조)
----------------------------------------------------------------------------------------------------------------------------------------------------------------
junit 으로 controller test 시도 중 Unsatisfied dependency expressed through constructor parameter 0 오류
> 스프링 빈의 순환 종속성 문제 (domain 클래스를 생성자로 의존성 주입하지 않고 클래스 필드를 통한 의존성 주입해서 발생한 것으로 추측)
> domain 클래스의 @component 를 삭제해줌
----------------------------------------------------------------------------------------------------------------------------------------------------------------
@Service,@Controller,@Component 차이
@Component :: Spring에서 관리되는 객체임을 표시하기 위해 사용하는 가장 기본적인 annotation
@Controller :: MVC 패턴에서 컨트롤러 역할을 하는 클래스에 붙여주고 @RequestMapping를 사용할 수 있음
@Service / @Repository :: 비즈니스 로직이나 respository layer 호출하는 method에 사용
>> @Controller @Service @Repository는 MVC 패턴에 맞게 사용되는(bean객체를 만듬) 특화된 어노테이션이고 그 외에는 @Component를 사용 (나중에 AOP에서 어노테이션에 따라 PointCut을 할 수 있기 때문에 구분해서 사용하는게 좋음
----------------------------------------------------------------------------------------------------------------------------------------------------------------
MockMvc 객체란? · 서블릿 컨테이너의 구동 없이, 시뮬레이션된 MVC 환경에 모의 HTTP 서블릿 요청을 전송하는 기능을 제공하는 유틸리티 클래스