반응형
싱글톤으로 띄우면 끝
Method[] methods = memberController.getClass().getDeclaredMethods();
for(Method method : methods) {
UtilsLog.getInstance().info(TAG, method.toString());
}
런타임시에 실행되는 이 코드.
멤버컨트롤러에 어떤 메서드가 있는지 확인
메서드의 파라미터까지 확인 가능
Method[] methods = memberController.getClass().getDeclaredMethods();
for(Method method : methods) {
UtilsLog.getInstance().info(TAG, method.getName());
}
Method[] methods = memberController.getClass().getDeclaredMethods();
for(Method method : methods) {
UtilsLog.getInstance().info(TAG, method.getName());
String idf = identifier.replace("/", "");
if(idf.equals(method.getName())) { // 요청 주소와 같은 이름이 있으면
UtilsLog.getInstance().info(TAG, idf + " 메서드를 실행합니다.");
try {
method.invoke(memberController, req, resp);
} catch (Exception e) {
e.printStackTrace();
}
}
}
인터페이스는 기본적으로 앞에 골뱅이를 붙이면 어노테이션으로 만들어진다.
package site.metacoding.reflect.config.web;
public @interface RequestMapping {
}
컨트롤러의 메서드에 @RequestMapping을 붙여주고 얘가 붙어있는 애를 디스패쳐서블릿에서 찾아볼것이다.
이대로 찾아보면 JVM이 인식하지 못한다.
어노테이션의 범위를 지정해줘야한다.
JVM이 쌩까지 못하게 설정해주자.
package site.metacoding.reflect.config.web;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.METHOD}) // 타겟범위 : 메서드 위에만 붙은 어노테이션
@Retention(RetentionPolicy.RUNTIME) // JVM 런타임시에 읽어라
public @interface RequestMapping {
}
타겟지정을 안하면 디폴트가 전체인갑다.
범위에 대해 테스트해보고 블로깅하자.
반응형