首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Spring的引文IOC

2012-10-06 
Spring的注解IOCJava注解方式出来很长时间了,迟迟偷懒,对此不曾多加理会。今晚大致看了一下Spring的注解实

Spring的注解IOC

Java注解方式出来很长时间了,迟迟偷懒,对此不曾多加理会。今晚大致看了一下Spring的注解实现,果然省略不少往日Spring XML文件的编写和维护的工作。

?

??使用注解定义Boss类,名称:boss,范围:prototype

?

@Component("boss")@Scope("prototype")public class Boss {@Autowiredprivate Car car;@Autowiredprivate Office office;public Car getCar() {return car;}public void setCar(Car car) {this.car = car;}public Office getOffice() {return office;}public void setOffice(Office office) {this.office = office;}@Overridepublic String toString() {return "car:" + car + "\n" + "office:" + office;}@PostConstructpublic void postConstruct1() {System.out.println("postConstruct1");}@PreDestroypublic void preDestroy1() {System.out.println("preDestroy1");}}

?

?? 在Spring XML文件中声明如下内容:用于Spring容器从哪里扫描Bean对象(提供regex、aspectj两种表达式)

<context:component-scan base-package="ioc.annotation.example6"><context:include-filter type="regex"expression="com\.annotation\.example6\..*" /><context:exclude-filter type="aspectj"expression="ioc.annotation.example6.service..*" /></context:component-scan>
?

热点排行