SpringBoot排除⾃动配置
springboot结构SpringBoot的⾃动配置给我们开发带来了极⼤的便利,但有些时候也带来了⼀些问题。
问题场景:
该项⽬是基于Springboot + dubbo的微服务架构,框架结构web + facade + service,某个模块的facade引⽤了Spring
Security的pom⽂件为了继承其中的接⼝,导致实现该facade接⼝的service启动时报springsecurity中XXXConfiguration中
XXXMethod不到;本意为实现springsecurity中相关接⼝被web层调⽤,wen层才是真正需要继承springsecurity,故该service需要
排除springsecurity相关⾃动配置;
解决过程:
⾸先贴上报错信息:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method setAuthenticationConfiguration in org.fig.figuration.WebSecurityConfigurerAdapter requir Action:
Consider defining a bean of type 'org.fig.figuration.AuthenticationConfiguration' in your configuration.
根据报错信息知道springboot在配置WebSecurityConfigurerAdapter时发⽣了错误,springboot还是很⼈性化的,启动时开启
debug⽇志级别会打印所有AutoConfiguration信息, 搜索启动⽇志查WebSecurityConfigurerAdapter;
2019-01-15 20:10:30.880 [main] DEBUG o.s.b.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'managementContextReso
2019-01-15 20:10:30.887 [main] DEBUG o.s.beans.factory.annotation.InjectionMetadata - Registered injected element on class [org.springframework.boot.actuat 2019-01-15 20:10:30.887 [main] DEBUG o.s.beans.factory.annotation.InjectionMetadata - Registered injected element on class [org.springframework.boot.actuat 2019-01-15 20:10:30.888 [main] DEBUG o.s.beans.factory.annotation.InjectionMetadata - Registered injected element on class [org.springframework.boot.actuat 2019-01-15 20:10:30.888 [main] DEBUG o.s.beans.factory.annotation.InjectionMetadata - Registered injected element on class [org.springframework.boot.actuat 2019-01-15 20:10:30.888 [main] DEBUG o.s.beans.factory.annotation.InjectionMetadata - Registered injected element on class [org.springframework.boot.actuat 2019-01-15 20:10:30.888 [main] DEBUG o.s.b.factory.support.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.boot.actuate.autoconfigu 2019-01-15 20:10:30.888 [main] DEBUG o.s.beans.factory.annotation.InjectionMetadata - Processing injected element of bean 'org.springframework.boot.actuate 2019-01-15 20:10:30.888 [main] DEBUG o.s.b.f.a.AutowiredAnnot
ationBeanPostProcessor - Autowiring by type from bean name 'org.springframework.boot.actua 2019-01-15 20:10:30.888 [main] DEBUG o.s.beans.factory.annotation.InjectionMetadata - Processing injected element of bean 'org.springframework.boot.actuate 2019-01-15 20:10:30.889 [main] DEBUG o.s.beans.factory.annotation.InjectionMetadata - Processing injected element of bean 'org.springframework.boot.actuate
根据⽇志信息得知是ManagementWebSecurityAutoConfiguration负责加载WebSecurityConfigurerAdapter配置,在
springboot启动类加上排除即可。
@SpringBootApplication(exclude={SecurityAutoConfiguration.class, OAuth2AutoConfiguration.class,SecurityFilterAutoConfiguration.class,ManagementWe

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。