springboot学习4

Spring手动装配之Spring 模式注解装配
1、模式注解

Spring Framework 注解场景起始版本
@Repository数据仓储模式注解2.0
@Component通用组件2.5
@Service服务2.5
@ControllerWeb控制器2.5
@Configuration配置类3.0

2、装配方式
1)<context:component-scan> (since spring2.5)

<?xml version="1.0" encoding="UTF-8"?>
<beans	xmlns="http://www.springframework.org/schema/beans"
		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xmlns:context="http://www.springframework.org/schema/context"
		xsi:schemaLocation="http://www.springframework.org/schema/beans
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context.xsd">
		<!-- 注解驱动 -->
		<context:annotation-config/>
		<!-- 把被 @Component 或者其 Annotation 标记的类,注册为 Spring Bean -->
		<context:component-scanbase-package="com.example.learndemo"/>
</beans>

2)@ComponentScan方式(since spring 3.1)

	@ComponentScan(basePackages="com.example.learndemo")
	public class SpringConfiguration { 
		//...
	}

3、自定义模式注解

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Repository
public @interface ARepository {
	String value() default"";
}
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@ARepository
public @interface BRepository {
	String value() default"";
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值