//SampleController.java
@PreAuthorize("hasAnyRole('ROLE_ADMIN','ROLE_MEMBER)")
@GetMapping("/annoMember")
public void doMember2(){}
@Secured({"ROLE_ADMIN"})
@GetMapping("/annoAdmin")
public void doAdmin2(){}
※컨트롤러에 사용하는 스프링 시큐리티의 어노테이션을 활성화하기 위해서는 security-context.xml이 아닌 servlet-context.xml에 설정을 추가해야 한다.
<!--servlet-context.xml으로 설정-->
<security:global-method-security pre-post-annotations="enabled" secured-annotations="enabled">
//ServletConfig.java로 설정
@EnableWebMvc
@ComponentScan(basePackages = {"org.tmkim.contorller"})
@EnableGlobalMethodSecurity(prePostEnalbed=true, securedEnabled=true)
public class ServletConfig implements WebMvcConfigurer{}