记录一下遇到的错误 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. 通信传输利器Netty(Net is DotNetty)介绍

    (先埋怨一下微软大大)我们做NET开发,十分羡慕JAVA上能有NETTY, SPRING, STRUTS, DUBBO等等优秀框架,而我们NET就只有干瞪眼,哎,无赖之前生态圈没做好,恨铁不成钢啊.不 ...

  2. day23单例模式 , 日志处理 , 项目结构目录

    # day23笔记 ## 一.补充,作业 ### 1.字符串格式化 ```pythonmsg = "我是%(n1)s,年龄%(n2)s" % {'n1': 'alex', 'n2' ...

  3. 利用JS写一个计算平方的网页

    <!-- 计算一个数的平方并显示出来 --> <!DOCTYPE html> <html> <head> <meta charset=" ...

  4. GBDT原理及利用GBDT构造新的特征-Python实现

    1. 背景 1.1 Gradient Boosting Gradient Boosting是一种Boosting的方法,它主要的思想是,每一次建立模型是在之前建立模型损失函数的梯度下降方向.损失函数是 ...

  5. junit测试

    /**ssm框架测试service**/ import com.alibaba.fastjson.JSON; import com.raycloud.waimai.customer.center.po ...

  6. selenium+webservice进行百度登录

    from selenium import webdriverimport time driver = webdriver.Chrome()driver.get("https://www.ba ...

  7. 使用Sales_data类

    写一段程序程序实现求两次交易相加结果的功能.程序的输入是下面这两条交易记录: 0-201-783456-X 3 20.00 0-201-783456-X 3 25.00 程序的结构如下: #inclu ...

  8. 最小生成树--克鲁斯卡尔算法(Kruskal)

    按照惯例,接下来是本篇目录: $1 什么是最小生成树? $2 什么是克鲁斯卡尔算法? $3 克鲁斯卡尔算法的例题 摘要:本片讲的是最小生成树中的玄学算法--克鲁斯卡尔算法,然后就没有然后了. $1 什 ...

  9. 【转载】大白话Docker入门(一)

    原文:https://yq.aliyun.com/articles/63035 随着docker现在越来越热门,自己也对docker的好奇心也越来越重,终于忍不住利用了一些时间把docker学习一遍. ...

  10. android TextView加载html 过滤所有标签,保留换行标签

    情景: TextView加载后端接口获取到的html富文本 遇到的问题: 客户端通过接口取到的数据如下: <p style="margin-top: 0px; margin-botto ...