记录一下遇到的错误 org.springframework.beans.factory.parsing.BeanDefinitionParsingException:

使用环境:spring 4.1.6

代码:

类1 配置类

@Configuration
@Import(value= {Sky.class,MyImportSelector.class})
public class MainConfig3 {

}

类2

public class MyImportSelector implements ImportSelector {

public String[] selectImports(AnnotationMetadata importingClassMetadata) {
//        String className = importingClassMetadata.getClassName();
//        System.out.println(className);
        return new String [] {"com.leon.pojo.Dog","com.leon.pojo.Sky","com.leon.pojo.Bird"};
    }
}

类3 测试类

public class MainTest {

AnnotationConfigApplicationContext config = new AnnotationConfigApplicationContext(MainConfig3.class);

@Test
        public void testImport() {
            String[] names = config.getBeanDefinitionNames();
            for(String st : names) {
                System.out.println(st);
            }
        }

很简单的一个导入bean注解,测试代码

在使用import的时候报错:

org.springframework.beans.factory.parsing.BeanDefinitionParsingException:

Configuration problem: com.leon.pojo.Sky was @Import'ed but is not annotated with @Configuration nor does it declare any @Bean methods; it does not implement ImportSelector or extend ImportBeanDefinitionRegistrar. Update the class to meet one of these requirements or do not attempt to @Import it.
Offending resource: class com.leon.pojo.Sky

解决方案:

1.在导入的bean类上加上@Repository  这样就能正常使用

2.把版本升级到4.2.6 (测试可用) 或者更高

关于使用spring版本4.1.6注解@Import报错的更多相关文章

  1. Spring boot Unable to start embedded Tomcat报错 java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()

    Spring boot Unable to start embedded Tomcat 报错 java.lang.NoSuchMethodError: javax.servlet.ServletCon ...

  2. idea操作 clone项目、 import项目所有注解全部报错

    操作:从现有的git上边clone项目,前提是开发工具,开发环境都一样错误类型:所有的注解全部报错 原因: 是选择了Create from existing source 一路Next下去,Maven ...

  3. 如何解决spring boot 项目导入依赖后代码报错问题

    如何解决spring boot 项目导入依赖后代码报错问题 2020-08-15  14:17:18 代码截图如图所示(由于本人问题已经解决,没来得及截图,所以在网上找了一张图片)

  4. Spring Boot接入 apollo 后启动 dubbo 报错

    原文地址:https://xobo.org/spring-boot-apollo-dubbo-xml-error/ 某Spring Boot项目接入 apollo 后启动 dubbo 报错Caused ...

  5. 1.1.6版本Druid连接MSSQLServer 2008 R2报错The query timeout value -1 is not valid. #2210

    https://github.com/alibaba/druid/releases/tag/1.1.8问题已修复,请使用新版本 xhhwc commented on 21 Dec 2017 1.1.6 ...

  6. 使用idea引入注解@SpringBootApplication报错Cannot resolve symbol 'SpringBootApplication'

    我在使用idea时,在类上使用注解@SpringBootApplication,但是一直报错. Cannot resolve symbol 'SpringBootApplication' 网络上有很多 ...

  7. Eclipse 配置spring boot pom.xml第1行报错的两种解决办法

    现象 通过spring boot项目导入eclipse后,pom.xml文件的第一行总是报错.这里使用的spring版本是2.1.5,2.1.4以前的版本等其他版本的spring没有这个问题. 解决办 ...

  8. JDK版本过高,导致Eclipse报错

    1.JDK版本如果比较高,而使用的eclipse版本比较低,导致在eclispe中不能识别而报错.   2.点击Attach Source添加rt.jar后,又出现如下错误 3.这样的错误就是由于ec ...

  9. eclipse spring 配置文件xml校验时,xsd报错

      1.情景展示 eclipse中,spring配置文件报错信息如下: 配置文件头部引用信息为: <?xml version="1.0" encoding="UTF ...

随机推荐

  1. 利用GitHub Pages和Bootstrap创建个人网站

    作为一名想要想找前端实习的即将毕业的学生,我最近意识到拥有个人网页会使自己的简历更容易被注意到.本文主要是我创建过程及个人心得,有些操作我也是第一次,所以难免在解释中会有错误.另外说明一下,我的电脑是 ...

  2. Spring Cloud中关于Feign的常见问题总结

    一.FeignClient接口,不能使用@GettingMapping 之类的组合注解 代码示例: @FeignClient("microservice-provider-user" ...

  3. vue md5

    安装 cnpm install js-md5 --save 使用 import md5 from 'js-md5' md5('要加密的内容')

  4. 基于jeesite的cms系统(六):Lucene全文搜索引擎

    1.lucene初始化 // @Value("${lucene.index.path}") private String indexPath = "/Users/vito ...

  5. 防止html页面缓存

    1.增加如下头 <meta http-equiv="Expires" content="0"> <meta http-equiv=" ...

  6. C# NPOI 操作Excel 案例

    1.加入NPOI 程序集,使用nuget添加程序集 2.引用NPOI程序集 private IWorkbook ExportExcel(PrintQuotationOrderViewModel mod ...

  7. centos7 nginx配置ssl证书实现https访问同时http访问

    1,首先将你申请到的nginx 分类下的ssl证书上传到nginx的config下(可以新建一个目录叫ssl.) 2.修改nginx的config配置 server {listen 80;(监听80端 ...

  8. vue 前端框架 (三)

    VUE 生命周期 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...

  9. 「luogu2387」[NOI2014] 魔法森林

    「luogu2387」[NOI2014] 魔法森林 题目大意 \(n\) 个点 \(m\) 条边的无向图,每条边上有两个权值 \(a,b\),求从 \(1\) 节点到 \(n\) 节点 \(max\{ ...

  10. 机器学习基石8-Noise and Error

    注: 文章中所有的图片均来自台湾大学林轩田<机器学习基石>课程. 笔记原作者:红色石头 微信公众号:AI有道 上一节课,我们主要介绍了VC Dimension的概念.如果Hypothese ...