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

[Spring]@Autowired 的应用

2012-11-08 
[Spring]@Autowired 的使用beans xmlnshttp://www.springframework.org/schema/beans?xmlns:xsihttp

[Spring]@Autowired 的使用
<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-2.0.xsd
?http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
?<context:annotation-config></context:annotation-config>
?<bean id="auto123"? value="Jordan"></property>
?</bean>
?<bean id="auto"? autowire-candidate="false">
??<property name="name1" value="Crystal"></property>
?</bean>
?<bean id="autowire1" >
??<property name="helloWord" value="Michael"></property>
?</bean>
?
</beans>

2.AutoWireBean2

package org.michael.spring.demo.autowire;

import org.springframework.beans.factory.annotation.Autowired;

public class AutoWireBean2 {
?
?private String helloWord;?
?@Autowired
?private AutoWireBean auto;
?public String getHelloWord() {
??return helloWord;
?}
?public void setHelloWord(String helloWord) {
??this.helloWord = helloWord;
?}
?public AutoWireBean getAuto() {
??return auto;
?}
?
}

注意,这里的auto可以不用写set方法

热点排行