package com.h3.core;
import org.springframework.beans.factory.annotation.value;
import org.springframework.stereotype.component;
@component("customerbean")
public class customer {
@value("#{'h3'.touppercase()}")
private string name;
@value("#{pricebean.getspecialprice()}")
private double amount;
public string getname() {
return name;
}
public void setname(string name) {
this.name = name;
}
public double getamount() {
return amount;
}
public void setamount(double amount) {
this.amount = amount;
}
@override
public string tostring() {
return "customer [name=" + name + ", amount=" + amount + "]";
}
}
package com.h3.core;
import org.springframework.stereotype.component;
@component("pricebean")
public class price {
public double getspecialprice() {
return new double(199.09);
}
}
输出
customer [name=h3, amount=199.09]
@value("#{'h3'.touppercase()}")
private string name;
在 ‘pricebean‘ bean上调用getspecialprice() 方法
@value("#{pricebean.getspecialprice()}")
private double amount;
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
xsi:schemalocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="customerbean" class="com.h3.core.customer">
<property name="name" value="#{'h3'.touppercase()}" />
<property name="amount" value="#{pricebean.getspecialprice()}" />
</bean>
<bean id="pricebean" class="com.h3.core.price" />
</beans>
输出
customer [name=h3, amount=199.09]