No qualifying bean of type 'com.yubai.el.ELConfig' available

Dear 丶 2022-06-11 09:56 183阅读 0赞
  1. Aug 04, 2017 3:36:39 PM org.springframework.context.annotation.AnnotationConfigApplicationContext prepareRefresh
  2. INFO: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@49097b5d: startup date [Fri Aug 04 15:36:39 CST 2017]; root of context hierarchy
  3. Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.yubai.el.ELConfig' available
  4. at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:353)
  5. at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:340)
  6. at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1090)
  7. at com.yubai.el.Main.main(Main.java:9)

源代码:

  1. package com.yubai.el;
  2. import org.springframework.context.annotation.AnnotationConfigApplicationContext;
  3. public class Main {
  4. public static void main(String[] args) {
  5. AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext("ELConfig.class");
  6. ELConfig resourceService = context.getBean(ELConfig.class);
  7. resourceService.outputResource();
  8. context.close();
  9. }
  10. }

出错原因:

从错误信息可知:没有此bean注入容器中,所以可能没有用@Service或者@Bean注入此类。还有可能是别的错误导致,如上错误。

AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(“ELConfig.class”);
AnnotationConfigApplicationContext作为spring容器,接收输入一个配置类作为参数。接收的类不要加双引号。

修改代码如下:

  1. package com.yubai.el;
  2. import org.springframework.context.annotation.AnnotationConfigApplicationContext;
  3. public class Main {
  4. public static void main(String[] args) {
  5. AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ELConfig.class);
  6. ELConfig resourceService = context.getBean(ELConfig.class);
  7. resourceService.outputResource();
  8. context.close();
  9. }
  10. }

此时运行正常

发表评论

表情:
评论列表 (有 0 条评论,183人围观)

还没有评论,来说两句吧...

相关阅读