public class SampleRealm extends AuthorizingRealm{
@Autowired
private LoginService loginService;
......
}
现象在自定义AuthorizingRealm子类SampleRealm中Service类无法注入成功
抛出该异常 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type,首先我回去检测LoginService子类是否做了如下Service层定义
@Service("loginService")
public class LoginServiceImpl implements LoginService {},检查已经定了说明代码编写的没问题;
然后查找配置文件是否有问题,首先要了解web.xml的启动原理,可以查看该文章http://blog.csdn.net/ahou2468/article/details/69948990(SpringMVC启动过程详解(li)),会发现首先会读取Spring监听器配置类ContextLoaderListener,它读取web.xml中配置的context-param中的配置文件,提前在web容器初始化前准备业务对应的Application context;将创建好的Application context放置于ServletContext中,为springMVC部分的初始化做好准备:
context-param参数配置如下: