@RequestMapping 애노테이션을 메타 애노테이션으로 사용하기
메타(Meta) 애노테이션
조합(Composed) 애노테이션
@Documented
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME) // 기본값은 class, 클래스를 로딩하는 순간 사라짐
@RequestMapping(method = RequestMethod.GET, value = "/hello")
public @interface GetHelloMapping {
}
@Controller
public class SampleController {
@GetHelloMapping
@ResponseBody
public String hello(){
return "hello";
}
}
@RunWith(SpringRunner.class)
@WebMvcTest
public class SampleControllerTest {
@Autowired
MockMvc mockMvc;
@Test
public void helloTest() throws Exception{
mockMvc.perform(options("/hello"))
.andDo(print())
.andExpect(status().isOk());
}
}
@Retention
@Target
@Documented
참고