Parameter 0 of method setObjectPostProcessor in WebSecurityConfigurerAdapter

SpringBoot+Shiro+Feign 时运行出现。

Exception:

Description:

Parameter 0 of method setObjectPostProcessor in org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter required a bean of type 'org.springframework.security.config.annotation.ObjectPostProcessor' that could not be found.


Action:

Consider defining a bean of type 'org.springframework.security.config.annotation.ObjectPostProcessor' in your configuration.

RestApplication中

@SpringBootApplication
@ServletComponentScan
@EnableFeignClients
@EnableCircuitBreaker
@EnableEurekaClient
@EnableDiscoveryClient
@EnableHystrix
//屏蔽activiti rest默认的basic authentication,使用shiro+jwt的验证替代
@EnableAutoConfiguration(exclude = {
        org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration.class,
        org.activiti.spring.boot.SecurityAutoConfiguration.class

})
public class RestApplication  extends SpringBootServletInitializer {

//内容省略……
}

解决办法:

新建一个类继承 WebSecurityConfigurerAdapter。

如:

MyWebSecurityConfigurerAdapter.java

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.ObjectPostProcessor;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class MyWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {

 @Override
    protected void configure(HttpSecurity http) throws Exception {
//CSRF默认支持的方法: GET|HEAD|TRACE|OPTIONS,不支持POST ,不是我们想要的,故取消CSRF防御
        http.csrf().disable();
    }

}

    原文作者:光影路西法
    原文地址: https://www.jianshu.com/p/d6e654bf6ce4
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞