spring @PreAuthorize not working with @EnableGlobalMethodSecurity(prePostEnabled = true)

前端 未结 1 2083
南笙
南笙 2021-01-03 08:33

Here is my code:

@Configuration
@ComponentScan(basePackages = \"com.webapp\")
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public cl         


        
相关标签:
1条回答
  • 2021-01-03 08:56

    Normally, Spring Security becomes available in the root application context and Spring MVC beans are initialized in a child context. Hence org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor can't detect your controller beans because they live in a child context that is unknown to the root context.

    @EnableGlobalMethodSecurity or <global-method-security> has to be placed inside the same configuration class or xml file where your Spring MVC configration lives in order to enable @PreAuthorize and @PostAuthorize.

    0 讨论(0)
提交回复
热议问题