之前,我们一直都是这样;
public class P {
private Car car;
public Car getCar() {
return car;
}
public void setCar(Car car) {
this.car = car;
}
}
然后在xml中还要配置
<bean id="p" class="com.sp.P">
<property name="car" ref="car"></property>
</bean>
然后才可以使用这个bean;
可是还有一个更简洁的方式,还可以这样:
@Component("people")
public class People {
@Resource
private Car car;
public Car getCar() {
return car;
}
}
然后xml中这样:
<context:component-scan base-package="com.sp"/>
<context:annotation-config />
<bean id="car" class="com.sp.Car">
<property name="name" value="宝马"></property>
<property name="price" value="9999"></property>
</bean>
运行结果一样
- 大小: 69.3 KB
分享到:
相关推荐
Spring annotation 样例
Spring Annotation
spring annotation注解 使用Spring注解来注入属性
spring的Annotation注解.
NULL 博文链接:https://cyhcheng.iteye.com/blog/390551
Spring的Annotation配置相关讲义
详解 Spring 3.0 基于 Annotation 的依赖注入实现。。详解 Spring 3.0 基于 Annotation 的依赖注入实现。。
花了些时间做了一个实验,彻底弄懂了spring Annotation注入的方式。凡带有@Component,@Controller,@Service,@Repository 标志的等于告诉Spring这类将自动产生对象,而@Resource则等于XML配置中的ref,告诉spring此处...
Spring_Annotation_AOP
关于Spring annotation的详细介绍,包括 @Component,@Autowired 等,感觉还不错。
Spring+mybatis annotation形式 进行增删查改,使用maven容器,配置完整,自己运行多次无问题
NULL 博文链接:https://dolphin-ygj.iteye.com/blog/548314
SpringMVC Spring MyBatis 框架整合 Annotation Maven Project
Spring IOC Annotation 注入 学习实例
spring annotation 从入门到精通
spring annotation 注解 maven 配套的源码
spring annotation example source code java maven
Spring注解开发代码+脑图+源码分析+spingmvc源码分析
spring使用annotation整合dwr笔记 spring使用annotation整合dwr笔记 spring使用annotation整合dwr笔记