shiro配置报错问题

开始在配置shiro一直报错

下面直接上代码,我开始的配置是这样的:

<!-- 配置权限管理器 -->  
    <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager"
   >    
        <!-- 使用下面配置的缓存管理器 -->  
        <property name="cacheManager" ref="cacheManager"/>   
        <property name="sessionMode" value="native"/>
        <!-- ref对应我们写的realm  MyShiro -->  
        <property name="realm" ref="myShiro"/>    
        <property name="sessionManager" ref="sessionManager"/>
    </bean>  

下面是报的错位置:

org.springframework.beans.factory.BeanCreationException:

 Error creating bean with name 'shiroFilter' defined in class path resource [applicationContext-shiro.xml]: 

BeanPostProcessor before instantiation of bean failed; 

nested exception is org.springframework.beans.factory.BeanCreationException: 

Error creating bean with name 'org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor#0' 

defined in class path resource [applicationContext-shiro.xml]: 

Cannot resolve reference to bean 'securityManager' while setting bean property 'securityManager';

 nested exception is org.springframework.beans.factory.BeanCreationException:

 Error creating bean with name 'securityManager' defined in class path resource [applicationContext-shiro.xml]: 

Cannot resolve reference to bean 'myShiro' while setting bean property 'realm'; 

nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myShiro': 

Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: 

Could not autowire field: private com.kj.service.UserService com.kj.filter.

MyShiro.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:

 No qualifying bean of type [com.kj.service.UserService] found for dependency: 

expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations:

 {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=userService)}

接着下面的错误:

Caused by: org.springframework.beans.factory.BeanCreationException: 

Error creating bean with name 'securityManager' defined in class path resource [applicationContext-shiro.xml]: 

Cannot resolve reference to bean 'myShiro' while setting bean property 'realm';

 nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myShiro': 

Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException:

 Could not autowire field: private com.kj.service.UserService com.kj.filter.MyShiro.userService;

 nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 

No qualifying bean of type [com.kj.service.UserService] found for dependency: 

expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: 

{@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=userService)}

1.接着分析:

配置的包名检查过了没有什么问题。

2.接着分析:

是不是不能自动注入?

接着检查我的注解也都没有什么问题:

dao的注解:

import com.kj.domain.Permission;
/*
 * Permission对应的Dao接口类
 */
@Repository("permissionMapper")
public interface PermissionMapper {

service的注解:

@Service("userService")
public class UserServiceImpl implements UserService{
	@Autowired
	@Qualifier("userMapper")
	private UserMapper userMapper;

filter的 注解:

@Service
@Transactional
public class MyShiro extends AuthorizingRealm {

	    @Autowired
	    @Qualifier("userService")
	    private UserService userService;

最后!

在网上找资料才解决。

<!-- 配置权限管理器 -->  
    <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager"
    depends-on="permissionMapper,roleMapper,rolePermissionMapper,userMapper,userRoleMapper">    
        <!-- 使用下面配置的缓存管理器 -->  
        <property name="cacheManager" ref="cacheManager"/>   
        <property name="sessionMode" value="native"/>
        <!-- ref对应我们写的realm  MyShiro -->  
        <property name="realm" ref="myShiro"/>    
        <property name="sessionManager" ref="sessionManager"/>
    </bean>  

就是在自定义realm中,一定要用depends-on加入所有的userService依赖持久层里面的dao。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用和都提到了"NOAUTH Authentication required"这个错误,它的含义是在连接Redis时没有进行身份验证。这个错误通常出现在使用密码连接Redis时没有提供正确的密码或者没有进行身份验证的情况下。 而引用则提到了在整合Shiro时出现了相同的错误。这可能是因为在配置Shiro-Redis的过程中没有正确进行身份验证所导致的。 要解决这个问题,需要确保在连接Redis时提供正确的密码,并且在Shiro-Redis的配置中进行正确的身份验证设置。具体的解决方法可以按照以下步骤进行: 1. 确保Redis的密码正确,并在连接Redis时提供正确的密码。可以在连接Redis的代码中添加类似于以下的代码来进行密码验证: ```java Jedis jedis = new Jedis("hostname", port); jedis.auth("password"); ``` 2. 在Shiro-Redis的配置中,确保正确配置了身份验证。可以在Shiro配置文件中添加类似于以下的配置来启用Redis身份验证: ```xml <bean id="redisManager" class="org.crazycake.shiro.RedisManager"> <property name="host" value="hostname"/> <property name="port" value="port"/> <property name="password" value="password"/> </bean> <bean id="cacheManager" class="org.crazycake.shiro.RedisCacheManager"> <property name="redisManager" ref="redisManager"/> </bean> <bean id="sessionManager" class="org.crazycake.shiro.RedisSessionManager"> <property name="redisManager" ref="redisManager"/> </bean> <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager"> <property name="realm" ref="myRealm"/> <property name="cacheManager" ref="cacheManager"/> <property name="sessionManager" ref="sessionManager"/> </bean> ``` 通过以上步骤,你应该能够解决"NOAUTH Authentication required"的报错问题,并成功连接和操作Redis。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [redis客户端连接(error) NOAUTH Authentication required](https://blog.csdn.net/m0_67392126/article/details/124016723)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [shiro+redis过程中出现的问题](https://blog.csdn.net/qq_39659876/article/details/81381552)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值