No qualifying bean of type 'com.yubai.el.ELConfig' available
2017-08-04 15:45
531 查看
Aug 04, 2017 3:36:39 PM org.springframework.context.annotation.AnnotationConfigApplicationContext prepareRefresh INFO: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@49097b5d: startup date [Fri Aug 04 15:36:39 CST 2017]; root of context hierarchy Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.yubai.el.ELConfig' available at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:353) at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:340) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1090) at com.yubai.el.Main.main(Main.java:9)
源代码:
package com.yubai.el; import org.springframework.context.annotation.AnnotationConfigApplicationContext; public class Main { public static void main(String[] args) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext("ELConfig.class"); ELConfig resourceService = context.getBean(ELConfig.class); resourceService.outputResource(); context.close(); } }
出错原因:
从错误信息可知:没有此bean注入容器中,所以可能没有用@Service或者@Bean注入此类。还有可能是别的错误导致,如上错误。
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(“ELConfig.class”);
AnnotationConfigApplicationContext作为spring容器,接收输入一个配置类作为参数。接收的类不要加双引号。
修改代码如下:
package com.yubai.el; import org.springframework.context.annotation.AnnotationConfigApplicationContext; public class Main { public static void main(String[] args) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ELConfig.class); ELConfig resourceService = context.getBean(ELConfig.class); resourceService.outputResource(); context.close(); } }
此时运行正常
相关文章推荐
- No qualifying bean of type 'com.yubai.bean.BeanWayService' available
- No qualifying bean of type 'com.funo.oa.dao.PostDao' available问题解决:找不到dao的实现类
- FAQ(54):No qualifying bean of type 'com.Role.Service.RoleService' available: expected at least 1 bea
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.wei
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.cui
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.wan
- No qualifying bean of type 'org.apache.catalina.User' available
- No qualifying bean of type [com.dao.UserDao] found for dependency:
- NoSuchBeanDefinitionException: No qualifying bean of type 'net.shopxx.service.xxxService' available:
- No qualifying bean of type [com.hz.app.mgmt.system.mgr.SysComBaseSettingMgr] is defined
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.oskyhang.gbd.service.UserService] found for dependency: expected at least 1 bean which qualifies as aut
- 出现No qualifying bean of type [com.*.*.dao.InfoDao] found for :错误
- No qualifying bean of type 'javax.sql.DataSource' available: more than one 'primary' bean found
- No qualifying bean of type [com.shyy.web.service.TreeMapper] found for dependency
- No qualifying bean of type [com.jj.mapper.UserMapper] found for dependency
- No qualifying bean of type [com.*.*.dao.InfoDao] found for :错误!
- No qualifying bean of type [com.zc.service.IFancyService] found for dependency
- No qualifying bean of type [com.it.service.DeptService] found for dependency
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.lin
- 错误:No qualifying bean of type 'com.mongodb.MongoClient'