shiro配置报错问题

开始在配置shiro一直报错

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

  
        
          
           
        
          
            
        
      

下面是报的错位置:

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;


最后!

在网上找资料才解决。
  
        
          
           
        
          
            
        
      

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





你可能感兴趣的:(shiro配置报错问题)