您现在的位置是:首页 > 技术人生 > 后端技术后端技术
SpringBoot排除自动配置
高晓波2019-01-15【后端技术】人已围观
简介SpringBoot的自动配置给我们开发带来了极大的便利,但有些时候也带来了一些问题。
问题场景:
该项目是基于Springboot + dubbo的微服务架构,框架结构web + facade + service,某
SpringBoot的自动配置给我们开发带来了极大的便利,但有些时候也带来了一些问题。
问题场景:
该项目是基于Springboot + dubbo的微服务架构,框架结构web + facade + service,某个模块的facade引用了Spring Security的pom文件为了继承其中的接口,导致实现该facade接口的service启动时报springsecurity中XXXConfiguration中XXXMethod找不到;本意为实现springsecurity中相关接口被web层调用,wen层才是真正需要继承springsecurity,故该service需要排除springsecurity相关自动配置;
解决过程:
首先贴上报错信息:
根据报错信息知道springboot在配置WebSecurityConfigurerAdapter时发生了错误,springboot还是很人性化的,启动时开启debug日志级别会打印所有AutoConfiguration信息, 搜索启动日志查找WebSecurityConfigurerAdapter;
根据日志信息得知是ManagementWebSecurityAutoConfiguration负责加载WebSecurityConfigurerAdapter配置,在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.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter required a bean of type 'org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.security.config.annotation.authentication.configuration.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 'managementContextResolver'
2019-01-15 20:10:30.887 [main] DEBUG o.s.beans.factory.annotation.InjectionMetadata - Registered injected element on class [org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration$ManagementWebSecurityConfigurerAdapter$$EnhancerBySpringCGLIB$$3db9a4ce]: AutowiredMethodElement for public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.setApplicationContext(org.springframework.context.ApplicationContext)
2019-01-15 20:10:30.887 [main] DEBUG o.s.beans.factory.annotation.InjectionMetadata - Registered injected element on class [org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration$ManagementWebSecurityConfigurerAdapter$$EnhancerBySpringCGLIB$$3db9a4ce]: AutowiredMethodElement for public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.setTrustResolver(org.springframework.security.authentication.AuthenticationTrustResolver)
2019-01-15 20:10:30.888 [main] DEBUG o.s.beans.factory.annotation.InjectionMetadata - Registered injected element on class [org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration$ManagementWebSecurityConfigurerAdapter$$EnhancerBySpringCGLIB$$3db9a4ce]: AutowiredMethodElement for public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.setContentNegotationStrategy(org.springframework.web.accept.ContentNegotiationStrategy)
2019-01-15 20:10:30.888 [main] DEBUG o.s.beans.factory.annotation.InjectionMetadata - Registered injected element on class [org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration$ManagementWebSecurityConfigurerAdapter$$EnhancerBySpringCGLIB$$3db9a4ce]: AutowiredMethodElement for public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.setAuthenticationConfiguration(org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration)
2019-01-15 20:10:30.888 [main] DEBUG o.s.beans.factory.annotation.InjectionMetadata - Registered injected element on class [org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration$ManagementWebSecurityConfigurerAdapter$$EnhancerBySpringCGLIB$$3db9a4ce]: AutowiredMethodElement for public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.setObjectPostProcessor(org.springframework.security.config.annotation.ObjectPostProcessor)
2019-01-15 20:10:30.888 [main] DEBUG o.s.b.factory.support.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration$ManagementWebSecurityConfigurerAdapter' to allow for resolving potential circular references
2019-01-15 20:10:30.888 [main] DEBUG o.s.beans.factory.annotation.InjectionMetadata - Processing injected element of bean 'org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration$ManagementWebSecurityConfigurerAdapter': AutowiredMethodElement for public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.setApplicationContext(org.springframework.context.ApplicationContext)
2019-01-15 20:10:30.888 [main] DEBUG o.s.b.f.a.AutowiredAnnotationBeanPostProcessor - Autowiring by type from bean name 'org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration$ManagementWebSecurityConfigurerAdapter' to bean named 'org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5f0e9815'
2019-01-15 20:10:30.888 [main] DEBUG o.s.beans.factory.annotation.InjectionMetadata - Processing injected element of bean 'org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration$ManagementWebSecurityConfigurerAdapter': AutowiredMethodElement for public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.setTrustResolver(org.springframework.security.authentication.AuthenticationTrustResolver)
2019-01-15 20:10:30.889 [main] DEBUG o.s.beans.factory.annotation.InjectionMetadata - Processing injected element of bean 'org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration$ManagementWebSecurityConfigurerAdapter': AutowiredMethodElement for public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.setContentNegotationStrategy(org.springframework.web.accept.ContentNegotiationStrategy)
根据日志信息得知是ManagementWebSecurityAutoConfiguration负责加载WebSecurityConfigurerAdapter配置,在springboot启动类加上排除即可。
@SpringBootApplication(exclude={SecurityAutoConfiguration.class, OAuth2AutoConfiguration.class,SecurityFilterAutoConfiguration.class,ManagementWebSecurityAutoConfiguration.class})
Tags:java SpringBoot
很赞哦! ()
随机图文
-
SpringBoot排除自动配置
SpringBoot的自动配置给我们开发带来了极大的便利,但有些时候也带来了一些问题。 问题场景: 该项目是基于Springboot + dubbo的微服务架构,框架结构web + facade + service,某 -
Springboot集成quartz定时任务可视化配置
使用quartz定时任务已经有一段时间了,今天记录一下Springboot 2.x集成Quartz。 -
【转】GPT 应用开发和思考
在过去几个月的时间中,我们似乎正处于人工智能的革命中。除了大多数人了解的 OpenAI ChatGPT 之外,许多非常新颖、有趣、实用的 AI 应用也是层出不穷,并且在使用这些应用时时,笔者也确确实实的感受到了生产力的提高。 -
通过Redis限制API调用次数
最近在做微信公众号返利机器人,通过曲线救国的方式拿到的淘宝客工具商权限(用别人的App Key),在服务器搭建了透传程序。 使用过程中发现一个问题:阿里妈妈对淘宝API的调用频率有限制,报错信息反馈是40次/秒。