041 Spring Boot中排除功能的处理
这个问题,原本是没有注意,主要是理解的不够深刻。
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中排除功能的处理的更多相关文章
- Spring Boot中的注解
文章来源:http://www.tuicool.com/articles/bQnMra 在Spring Boot中几乎可以完全弃用xml配置文件,本文的主题是分析常用的注解. Spring最开始是为了 ...
- Spring boot中使用log4j
我们知道,Spring Boot中默认日志工具为logback,但是对于习惯了log4j的开发者,Spring Boot依然可以很好的支持,只是需要做一些小小的配置功能.Spring Boot使用lo ...
- Spring Boot 中使用 jpa
本文原文版权归 CSDN Hgihness 所有,此处为转载+技术收藏,如有再转请自觉于篇头处标明原文作者及出处,这是大家对作者劳动成果的自觉尊重!! 作者:Hgihness 原文:http://bl ...
- Spring boot中使用log4j记录日志
之前在Spring Boot日志管理一文中主要介绍了Spring Boot中默认日志工具(logback)的基本配置内容.对于很多习惯使用log4j的开发者,Spring Boot依然可以很好的支持, ...
- 004-集成maven和Spring boot的profile功能打包
参考地址:https://blog.csdn.net/lihe2008125/article/details/50443491 一.主要目标 1.通过mvn在命令行中打包时,可以指定相应的profil ...
- spring boot 中文文档地址
spring boot 中文文档地址 http://oopsguy.com/documents/springboot-docs/1.5.4/index.html Spring Boot 参考指 ...
- spring boot(三):Spring Boot中Redis的使用
spring boot对常用的数据库支持外,对nosql 数据库也进行了封装自动化. redis介绍 Redis是目前业界使用最广泛的内存数据存储.相比memcached,Redis支持更丰富的数据结 ...
- Spring Boot中的事务管理
原文 http://blog.didispace.com/springboottransactional/ 什么是事务? 我们在开发企业应用时,对于业务人员的一个操作实际是对数据读写的多步操作的结合 ...
- Spring Boot中使用Swagger2构建强大的RESTful API文档
由于Spring Boot能够快速开发.便捷部署等特性,相信有很大一部分Spring Boot的用户会用来构建RESTful API.而我们构建RESTful API的目的通常都是由于多终端的原因,这 ...
随机推荐
- 分页插件pagination.js
项目中有分页功能,之前都是自己写,样式不好看,功能也简单,就找了这个插件pagination.js 页面导入pagination.js html代码 <div class="list_ ...
- 打包APP
记得之前网上也有app打包平台,但是都会有所限制,或者增加广告等等,这里呢,介绍一款工具,可以自己将网站打包成app. wex5 (WeX5开源免费跨端开发工具-html5 app开发就用WeX5)官 ...
- Java_oracle超出打开游标的最大数的原因和解决方案
第一步:核查Oracle数据库 的游标的最大数 处理超出打开游标的最大数异常(ORA-01000: maximum open cursors exceeded) ORA-01000_maximum_o ...
- Oracle12c Data Guard搭建手册
Oracle12c Data Guard搭建手册 注:本文来源: 红黑联盟 < Oracle12c Data Guard搭建手册 > Oracle 12c 的DataGuard 是在CDB ...
- Confluence 6 警告的类型
有下面的一些类型的警告. 警告和知识库(Alert and KB) 级别(Level) 默认阈值(Default threshold) 可配置(Configurable) Low free disk ...
- Confluence 6 内存使用和需求和一些问题
系统备份和恢复 Confluence 的备份和恢复是与数据库中数据量的大小有关.这个操作可能会对 Confluence 的性能产生很多关键性的影响并且大量消耗内存.如果你在 Confluence 的 ...
- Confluence 6 下载和安装 MySQL 驱动
基于许可证的现在,我们没有将 MySQL 的数据库捆绑到 Confluence 中.需要将你的数据库驱动在 Confluence 中可用: 停止 Confluence. 访问 Database JDB ...
- cf1108E2 线段树类似扫描线
/* 有点像扫描线 思路:从左到右枚举每个点,枚举到点i时,把所有以i为起点的区间的影响删去 再加上以i-1为结尾的区间的影响 */ #include<bits/stdc++.h> usi ...
- 封装input 逐渐,且input插件必须带有默认值。
封装input 逐渐,且input插件必须带有默认值. 组件: <template> <div class="input-show"> <span c ...
- java 托盘 实现二级菜单
package com.zs; import java.awt.AWTException; import java.awt.CheckboxMenuItem; import java.awt.Fram ...