Spring boot - annotation

아기코딩단2·2022년 4월 20일
0

Front Controller 만들기

원래는 각각 controller 가 service 객체를 호출하고 DAO를 호출함
cotroller 가 jsp(get 호출)를 호출하고 servlet request(set 호출)를 호출함
=> 공통코드를 꺼내서 캡슐화 함 -> DispatcherServlet(<>)[페이지 컨트롤러의 공통 기능 수행 => 예외처리(예외처리 컴포넌트 라고 불러도 상관 없음), 뷰 컴포넌트(class를 묶어서 component라고 부름)] -> 각각의 controller 는 page controller(특정 페이지의 요청 처리) 가 됨 app/board/list 을 front controller 에 요청하게 되면 각각의 page controller 에 요청을 보냄

class 를 묶어서 component 를 만듦 => component 는 한개의 클래스로 이루어진 중간부품임

@SuppressWarnings("serial") => serial 관련 에러 띄우지마라는 뜻
@WebServlet("/app/*") => app 으로 들어오는 요청은 얘가 받아라

ServletRequest => http protocol 을 꺼낼 수 있는 기능이 없음
ServletRequest 을 바로 쓸 수 없으니 노란색 service 를 사용하면 됨

.getRequestDispatcher("/jsp/error.jsp").forward = > include 대신 forward쓰는 이유는 그냥 출력하라는 뜻
include 인 경우는 response.setContentType 이렇게 content type 을 설정해줘야함

@Target(ElementType.TYPE) // 현재 정의하는 애노테이션은 오직 클래스나 인터페이스에만 붙일 수 있게 제한한다.
@Retention(RetentionPolicy.RUNTIME) // 현재 정의하는 애노테이션 정보를 JVM실행 중에 추출할 수 있게 허락한다.
//객체를 자동 생성하고 싶을 떄 붙이는 애노테이션

File path = new File("./bin/" + pakagePath);
System.out.println(path.getCanonicalPath()); 실제 위치를 알아내는 코드

private void createBeans(ServletContext 보관소) throws Exception {
String contextPath = 보관소.getRealPath("/");
System.out.println(contextPath);
}
=> 실제 위치를 알아내는 다른 코드

if (file.getName().endWith(".class") && file.getName().contains("$")) { => $는 중첩클래스

fully qualified => 패키지 명을 포함한 이름

Class<?> classInfo = Class.forName(className);
			  Component compAnno = classInfo.getAnnotaion(Component.class);
			  if (compAnno != null ) {
				  System.out.println(classInfo.getSimpleName()); 
``````````` => reflection API 라고 함

Spring framework 안쓰면 annotation 을 만들어줘야함

profile
레거시 학살자

0개의 댓글