Spring Auto Scan (XII)

1.Spring automatic scanning needs to be added as follows

This "context: component", which means, to enable automatic scanning feature in the Spring bean configuration file. base-package is specified storage components, Spring will scan the folder and find Bean (annotated as @Component) and registered to Spring container.

<context:component-scan base-package="com.yiibai.customer" />

Path packet may use wildcards apparatus, as follows:. Com * all files in the package com.

2. Auto Scan comment

By default, Spring lowercase characters in the first member - the 'CustomerService' to 'CustomerService'. The assembly can be retrieved to the name "customerService", the name can be retrieved by bean @Service ( "AAA") becomes AAA, annotations are several types:

@Component – 指示自动扫描组件。
@Repository – 表示在持久层DAO组件。
@Service – 表示在业务层服务组件。
@Controller – 表示在表示层控制器组件。

Note: Some @Repository, @Service or @Controller are annotated as @Component. Therefore, we can only use @Component automatically scan all the components? Yes, Spring will automatically scan @Component notes of all components.

3. Notes Filter

Comprising:
<context: the include filter-type = "cases. 5" expression = "follows" />
does not include:
<context: the exclude filter-type = "cases. 5" expression = "follows" />

type types are as follows:

1、type=annotation,必须由注解,过滤器扫描使用指定注解所标注的那些类。具体来说,就是@Component,@Service,@Repository,@Controller这几个构造型注解所在的类。
expression=有4个值,这种限定方式是必须有@Component等注解的。
org.springframework.stereotype.Component;
org.springframework.stereotype.Controller;
org.springframework.stereotype.Repository;
org.springframework.stereotype.Service;

2、type=assignable,注解不是必要的,过滤器扫描派生于expression属性所指定类型的那些类,所谓的派生,具体的实现类的路径。
expression=接口类路径

3、type=aspectj,过滤器扫描与expression属性所指定的AspectJ表达式所匹配的那些类。

4、type=custom,使用自定义的org.springframework.core.type.TypeFilter实现类,该类由expression属性指定。

5、type=regex,过滤器扫描类的名称与expression属性所指定的正则表达式所匹配的那些类。

As follows: not included in these documents are marked with @Service

<context:component-scan base-package="com.yiibai.customer" >
		<context:exclude-filter type="annotation" 
			expression="org.springframework.stereotype.Service" />		
</context:component-scan>

Guess you like

Origin blog.csdn.net/qq_36831305/article/details/89000359