我是新申請自動佈線兩beans.please檢查以下如何在兩個豆的春天使用自動佈線?
我的代碼Color.java
public class Color {
private String baseColor;
private String textureColor;
public String getBaseColor() {
return baseColor;
}
public void setBaseColor(String baseColor) {
this.baseColor = baseColor;
}
public String getTextureColor() {
return textureColor;
}
public void setTextureColor(String textureColor) {
this.textureColor = textureColor;
}
@Override
public String toString() {
return baseColor + " base skin color and " + textureColor + " texture color." ;
}
}
Behaviour.java
public class Behaviour{
private String behaviourType;
public String getBehaviourType() {
return behaviourType;
}
public void setBehaviourType(String behaviourType) {
this.behaviourType = behaviourType;
}
}
貓.java
public class Cat {
private String name;
private Color color;
private Behaviour behaviour;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color= color;
}
public Color getBehaviour() {
return behaviour;
}
public void setBehaviour(Behaviour behaviour) {
this.behaviour= behaviour;
}
@Override
public String toString() {
return "The " + name + " has " + color.toString();
}
}
的applicationContext.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd">
<bean id="color" class="com.javacodegeeks.snippets.enterprise.Color">
<property name="baseColor" value="white" />
<property name="textureColor" value="grey" />
</bean>
<bean id="cat" class="com.javacodegeeks.snippets.enterprise.Cat">
<property name="name" value="cat" />
<property name="color" ref="color" />
<property name="behaviour" ref="behaviour" />
</bean>
<bean id="behaviour" class="com.javacodegeeks.snippets.enterprise.Behaviour">
<property name="behaviourType" value="Somebevhaviour" />
</bean>
</beans>
它工作正常,但我想通過使用自動佈線(綽號)用於寫入applicationContext.xml文件