这个问题,原本是没有注意,主要是理解的不够深刻。

1.先看我的配置文件

 package com.springBoot.ioc.config;

 import com.springBoot.ioc.controller.StudentController;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType; /**
* @Desciption 配置文件
*/
/*@Configuration
public class MySpringBootConfig {
@Bean(name="student")
public Student getStu(){
Student student=new Student();
student.setId(1L);
student.setUsername("Tom");
student.setPassword("123456");
return student;
}
}*/
@Configuration
@ComponentScan(basePackages="com.springBoot.ioc.*",excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION,classes = StudentController.class)})
public class MySpringBootConfig{ }

2.然后运行程序,看报错信息

 9:51:13.797 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@67b92f0a: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,mySpringBootConfig]; root of factory hierarchy
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.springBoot.ioc.config.MySpringBootConfig]; nested exception is java.lang.IllegalArgumentException: @ComponentScan ANNOTATION type filter requires an annotation type: class com.springBoot.ioc.controller.StudentController
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:184)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:316)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:271)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:91)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:692)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:530)
at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:88)
at com.springBoot.ioc.test.IocTestDemo.main(IocTestDemo.java:17)
Caused by: java.lang.IllegalArgumentException: @ComponentScan ANNOTATION type filter requires an annotation type: class com.springBoot.ioc.controller.StudentController
at org.springframework.util.Assert.assignableCheckFailed(Assert.java:655)
at org.springframework.util.Assert.isAssignable(Assert.java:586)
at org.springframework.context.annotation.ComponentScanAnnotationParser.typeFiltersFor(ComponentScanAnnotationParser.java:142)
at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:102)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:288)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:202)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:170)
... 8 more Process finished with exit code 1

3.原因

  在excludedFilters中的class属性指定的是Controller,Service之类的,不是具体的类。

  应该是如下的程序:

 package com.springBoot.ioc.config;

 import com.springBoot.ioc.controller.StudentController;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.stereotype.Controller; /**
* @Desciption 配置文件
*/
/*@Configuration
public class MySpringBootConfig {
@Bean(name="student")
public Student getStu(){
Student student=new Student();
student.setId(1L);
student.setUsername("Tom");
student.setPassword("123456");
return student;
}
}*/
@Configuration
@ComponentScan(basePackages="com.springBoot.ioc.*",excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION,classes = Controller.class)})
public class MySpringBootConfig{ }

4.注意点

  导包的时候,也不要出错。

041 Spring Boot中排除功能的处理的更多相关文章

  1. Spring Boot中的注解

    文章来源:http://www.tuicool.com/articles/bQnMra 在Spring Boot中几乎可以完全弃用xml配置文件,本文的主题是分析常用的注解. Spring最开始是为了 ...

  2. Spring boot中使用log4j

    我们知道,Spring Boot中默认日志工具为logback,但是对于习惯了log4j的开发者,Spring Boot依然可以很好的支持,只是需要做一些小小的配置功能.Spring Boot使用lo ...

  3. Spring Boot 中使用 jpa

    本文原文版权归 CSDN Hgihness 所有,此处为转载+技术收藏,如有再转请自觉于篇头处标明原文作者及出处,这是大家对作者劳动成果的自觉尊重!! 作者:Hgihness 原文:http://bl ...

  4. Spring boot中使用log4j记录日志

    之前在Spring Boot日志管理一文中主要介绍了Spring Boot中默认日志工具(logback)的基本配置内容.对于很多习惯使用log4j的开发者,Spring Boot依然可以很好的支持, ...

  5. 004-集成maven和Spring boot的profile功能打包

    参考地址:https://blog.csdn.net/lihe2008125/article/details/50443491 一.主要目标 1.通过mvn在命令行中打包时,可以指定相应的profil ...

  6. spring boot 中文文档地址

    spring boot 中文文档地址     http://oopsguy.com/documents/springboot-docs/1.5.4/index.html Spring Boot 参考指 ...

  7. spring boot(三):Spring Boot中Redis的使用

    spring boot对常用的数据库支持外,对nosql 数据库也进行了封装自动化. redis介绍 Redis是目前业界使用最广泛的内存数据存储.相比memcached,Redis支持更丰富的数据结 ...

  8. Spring Boot中的事务管理

    原文  http://blog.didispace.com/springboottransactional/ 什么是事务? 我们在开发企业应用时,对于业务人员的一个操作实际是对数据读写的多步操作的结合 ...

  9. Spring Boot中使用Swagger2构建强大的RESTful API文档

    由于Spring Boot能够快速开发.便捷部署等特性,相信有很大一部分Spring Boot的用户会用来构建RESTful API.而我们构建RESTful API的目的通常都是由于多终端的原因,这 ...

随机推荐

  1. 【原创】大叔经验分享(40)hdfs关闭kerberos

    hadoop.security.authentication: Kerberos -> Simple hadoop.security.authorization: true -> fals ...

  2. Vue-tab选项卡

    <div id='test'> <ul class="nav" > <li v-for='(item,index) in dataNav' @clic ...

  3. socket-WebSocket-HttpListener-TcpListener服务端客户端的具体使用案例

    /// <summary> /// 启动服务监听的ip和端口的主线程 /// </summary> /// <param name="tunnelPort&qu ...

  4. Confluence 6 恢复一个空间

    你可以导出一个空间 – 包括页面,评论和附件到一个压缩的 XML 文件中,可选的你可以在 XML 文件中包括所有空间使用的附件.希望导入空间到其他的 Confluence 站点中,请按照下面的方法进行 ...

  5. 爬虫框架之Scrapy

    一.介绍 二.安装 三.命令行工具 四.项目结构以及爬虫应用简介 五.Spiders 六.Selectors 七.Items 八.Item Pipelin 九. Dowloader Middeware ...

  6. skipfish web Scrabble

    1.skipfish 网页扫描抓取 2.w3af web漏洞扫描

  7. cf1144G 将串分解成单调递增和递减子串(贪心)

    这算哪门子dp.. 具体做法就是贪心,建立两个vector存递增序列递减序列,操作过程中a可以合法地匀一个给b 就是判断第i个数放在递增序列里还是放在递减序列里,需要根据后面的数来进行决策 #incl ...

  8. A^B Mod C

    A^B Mod C 时间限制: 1 Sec  内存限制: 32 MB Problem Description 给出3个正整数A B C,求A^B Mod C. 例如,3 5 8,3^5 Mod 8 = ...

  9. Allegro PCB Design GXL (legacy) 由零散的对象构成一个Shape

    Allegro PCB Design GXL (legacy) version 16.6-2015 从DXF文件中导入板框之后,发现板框是由Line Segment.Arc Segment等对象组成, ...

  10. MongoDB数据库备份与还原、单表的导入导出

    -------------------MongoDB备份与恢复------------------- 1.MongoDB数据库备份     1.语法:         mongodump -h dbh ...