开始在配置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)}
配置的包名检查过了没有什么问题。
2.接着分析:
是不是不能自动注入?
接着检查我的注解也都没有什么问题:
dao的注解:
import com.kj.domain.Permission;
/*
* Permission对应的Dao接口类
*/
@Repository("permissionMapper")
public interface PermissionMapper {
@Service("userService")
public class UserServiceImpl implements UserService{
@Autowired
@Qualifier("userMapper")
private UserMapper userMapper;
@Service
@Transactional
public class MyShiro extends AuthorizingRealm {
@Autowired
@Qualifier("userService")
private UserService userService;