springboot配置多数据库后shiro报错

问题

springboot项目使用了shiro框架,后项目需要连接两个数据库,配置多数据库连接后shiro报错如下:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-10-05 21:44:06.306  INFO 34548 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'shiroConfig' of type [com.**.common.shiro.ShiroConfig$$EnhancerBySpringCGLIB$$a50d5c2b] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-10-05 21:44:06.316 ERROR 34548 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'getShiroFilterFactoryBean' defined in class path resource [com/**/common/shiro/ShiroConfig.class]: Unsatisfied dependency expressed through method 'getShiroFilterFactoryBean' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityManager' defined in class path resource [com/**/common/shiro/ShiroConfig.class]: Unsatisfied dependency expressed through method 'getDefaultWebSecurityManager' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shiroRealm': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.**.user.mapper.UserMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:769) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:509) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
	...

其中多数据连接方式在其他项目实践中没有问题,之前shiro在此项目中也可以正常运行

解决

参考了大佬的文章 https://knife.blog.csdn.net/article/details/119704109

原项目在自定义realm中使用了UserMapper,给UserMapper加上@Lazy注解,不再报上面的错误

原:

public class ShiroRealm extends AuthorizingRealm {
    @Resource
    private UserMapper userMapper;
	...
}

后:

public class ShiroRealm extends AuthorizingRealm {
	@Lazy
    @Resource
    private UserMapper userMapper;
	...
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值