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

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. 用layui搭建的后台框架

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. python-异常处理、元类

    一.异常处理 1.异常处理介绍: 异常是错误发生的信号,一旦程序出错就会产生一个异常,如果该异常没有被应用程序处理,那么该异常就会被抛出来,程序执行随之停止 2.异常通常包含三个部分 1.traceb ...

  3. mysql 中实现多条数据同时更新

    有时间我们需要对一张表进行批量数据的更新.首先我们想的是update 语句. 比如对一张订单表order_info 多条数据更新, update order_inifo set   order_cod ...

  4. 《MySQL5.7从入门到精通(视频教学版)》

    · 一:书籍PDF获取途径 pdf 文档 在 此QQ群(668345923) 的群文件里面 学习视频资源 二:书籍介绍 本书主要包括MySQL的安装与配置.数据库的创建.数据表的创建.数据类型和运算符 ...

  5. Java的两个实验程序

    日期:2018.10.07 星期五 博客期:015 Part1:----------------第一个是二柱子出30道小学数学题: 一.程序设计思想 本程序设计由三部分构成,第一部分因为循环30次的需 ...

  6. 基于多进程的Tcp套接字服务器

    服务端 import socketfrom multiprocessing import Process def task(c): print('顾客吃点啥') while True: data = ...

  7. Cpython支持的进程与线程

    一.multiprocessing模块介绍 python中的多线程无法利用CPU资源,在python中大部分情况使用多进程.python中提供了非常好的多进程包multiprocessing. mul ...

  8. LeetCode(92):反转链表 II

    Medium! 题目描述: 反转从位置 m 到 n 的链表.请使用一趟扫描完成反转. 说明:1 ≤ m ≤ n ≤ 链表长度. 示例: 输入: 1->2->3->4->5-&g ...

  9. 拓扑排序基础 hdu1258,hdu2647

    由这两题可知拓扑排序是通过“小于”关系加边建图的 hdu2647 /* 拓扑排序的原则是把“小于”看成有向边 此题反向建图即可 并且开num数组来记录每个点的应该得到的权值 */ #include&l ...

  10. 安装mysql后在/var/log/mysqld.log 中找不到临时密码

    centos7通过yum装完mysql,使用grep 'temporary password' /var/log/mysqld.log找不到root密码打开mysqld.log中根本没有tempora ...