spring boot 整合shiro 配置类报错问题

在尝试使用Spring Boot整合Shiro时遇到了配置类的报错,具体表现为自定义Realm类无法被正确装载,报错信息指出该类由JDK装载且不适用于自动代理。错误中提到的问题是由于Bean的类型不匹配导致,解决方案是将注入的myAutoRealm改为它的父类Realm。这是一个关于Spring Boot与Shiro集成中遇到的问题及解决办法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


这里传入的是下边返回的自定义Realm,下边是报错,报的是该类不能被装载,由jdk自己装载,这里不是太懂,记录一下,由于错误太长,不好截屏,直接复制错误内容

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

////////////////////////////////////////////////////////////////////
// _ooOoo_ //
// o8888888o //
// 88" . "88 //
// (| ^_^ |) //
// O\ = /O //
// ____/`---'\____ //
// .' \\| |// `. //
// / \\||| : |||// \ //
// / _||||| -:- |||||- \ //
// | | \\\ - /// | | //
// | \_| ''\---/'' | | //
// \ .-\__ `-` ___/-. / //
// ___`. .' /--.--\ `. . ___ //
// ."" '< `.___\_<|>_/___.' >'"". //
// | | : `- \`.;`\ _ /`;.`/ - ` : | | //
// \ \ `-. \_ __\ /__ _/ .-` / / //
// ========`-.____`-.___\_____/___.-`____.-'======== //
// `=---=' //
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //
// 佛祖保佑 永不宕机 永无BUG //
////////////////////////////////////////////////////////////////////
2018-01-09 00:42:22.862  INFO 8980 --- [           main] org.fsc.EnterBoot                        : Starting EnterBoot on PC-20160923LSVW with PID 8980 (D:\Users\Administrator\eclipse-workspace\SpringBoot\target\classes started by Administrator in D:\Users\Administrator\eclipse-workspace\SpringBoot)
2018-01-09 00:42:22.881  INFO 8980 --- [           main] org.fsc.EnterBoot                        : No active profile set, falling back to default profiles: default
2018-01-09 00:42:23.202  INFO 8980 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@79ad8b2f: startup date [Tue Jan 09 00:42:23 CST 2018]; root of context hierarchy
+++++++++++++++shiro配置被加载+++++++++++++++++++++
2018-01-09 00:42:28.476  INFO 8980 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'shiroConfiguration' of type [class org.fsc.MyShiro.ShiroConfig.ShiroConfiguration$$EnhancerBySpringCGLIB$$49dc09f0] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-01-09 00:42:28.553  INFO 8980 --- [           main] o.f.M.ShiroConfig.ShiroConfiguration     : --------------(shiro生命周期)lifecycleBeanPostProcessor已经加载----------------
2018-01-09 00:42:28.933  INFO 8980 --- [           main] o.f.M.ShiroConfig.ShiroConfiguration     : --------------cacheManager已经加载----------------
2018-01-09 00:42:31.553  INFO 8980 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'cacheManager' of type [class org.apache.shiro.cache.ehcache.EhCacheManager] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-01-09 00:42:32.003  INFO 8980 --- [           main] o.f.M.ShiroConfig.ShiroConfiguration     : --------------(shiro密码比较器)credentialsMatcher已经加载----------------
2018-01-09 00:42:32.029  INFO 8980 --- [           main] o.a.shiro.cache.ehcache.EhCacheManager   : Using existing EHCache named [passwordRetryCache]
2018-01-09 00:42:32.062  INFO 8980 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'credentialsMatcher' of type [class org.fsc.MyShiro.CredentialsMatcher.RetryLimitHashedCredentialsMatcher] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-01-09 00:42:32.115  INFO 8980 --- [           main] o.f.M.ShiroConfig.ShiroConfiguration     : --------------authRealm已经加载----------------
MyAutoRealm+++++++++++++++++++++++++++++++++++++++++++++++++++
2018-01-09 00:42:32.125  INFO 8980 --- [           main] o.a.shiro.cache.ehcache.EhCacheManager   : Cache with name 'org.fsc.MyShiro.MyRealm.MyAutoRealm.authorizationCache' does not yet exist.  Creating now.
2018-01-09 00:42:32.200  INFO 8980 --- [           main] o.a.shiro.cache.ehcache.EhCacheManager   : Added EhCache named [org.fsc.MyShiro.MyRealm.MyAutoRealm.authorizationCache]
2018-01-09 00:42:32.259  INFO 8980 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'myAutoRealm' of type [class org.fsc.MyShiro.MyRealm.MyAutoRealm] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-01-09 00:42:32.404  WARN 8980 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'shiroFilter' defined in class path resource [org/fsc/MyShiro/ShiroConfig/ShiroConfiguration.class]: Unsatisfied dependency expressed through method 'shiroFilter' parameter 0: Error creating bean with name 'securityManager' defined in class path resource [org/fsc/MyShiro/ShiroConfig/ShiroConfiguration.class]: Unsatisfied dependency expressed through method 'securityManager' parameter 0: Bean named 'myAutoRealm' is expected to be of type [org.fsc.MyShiro.MyRealm.MyAutoRealm] but was actually of type [com.sun.proxy.$Proxy51]; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'myAutoRealm' is expected to be of type [org.fsc.MyShiro.MyRealm.MyAutoRealm] but was actually of type [com.sun.proxy.$Proxy51]; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityManager' defined in class path resource [org/fsc/MyShiro/ShiroConfig/ShiroConfiguration.class]: Unsatisfied dependency expressed through method 'securityManager' parameter 0: Bean named 'myAutoRealm' is expected to be of type [org.fsc.MyShiro.MyRealm.MyAutoRealm] but was actually of type [com.sun.proxy.$Proxy51]; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'myAutoRealm' is expected to be of type [org.fsc.MyShiro.MyRealm.MyAutoRealm] but was actually of type [com.sun.proxy.$Proxy51]
Related cause: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'shiroFilter': Requested bean is currently in creation: Is there an unresolvable circular reference?
2018-01-09 00:42:32.477 ERROR 8980 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 


***************************
APPLICATION FAILED TO START
***************************


Description:


The bean 'myAutoRealm' could not be injected as a 'org.fsc.MyShiro.MyRealm.MyAutoRealm' because it is a JDK dynamic proxy that implements:




Action:


Consider injecting the bean as one of its interfaces or forcing the use of CGLib-based proxies by setting proxyTargetClass=true on @EnableAsync and/or @EnableCaching.

解决办法:

将传入的自定义myAutoRealm改为他的父类Realm就好了,理由还不解,有大佬懂么





评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值