Spring教程
作者: 时海 hadoop迷
@ComponentScan

ComponentScan注解用于指定扫描的路径,可以通过excludeFilters,includeFilters分别排除或包含部分组件

1、excludeFilters

package spring.example.anno;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.stereotype.Service;

@Configuration
@ComponentScan(value = {"spring.example.anno.user", "spring.example.anno.item"},
excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION,value = {Service.class})})
public class Config {
}

输出结果:


config
userController
userDao
itemController
itemDao
Service注解的bean被排除在外


@ComponentScan.Filter  type属性用于指定过滤时使用的类型,包括以下几种

FilterType.ANNOTATION :注解类型

FilterType.ASSIGNABLE_TYPE:具体的类

FilterType.ASPECTJ

FilterType.REGEX

FilterType.CUSTOM




一个创业中的苦逼程序员
  • 回复
隐藏