开始在配置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>