我需要使用基於xml的依賴注入將java.sql.Time
對象注入到Subject
bean中。將java.sql.Time對象注入bean - spring xml dependency injection
這是我的Subject
類定義。
public class Subject{
private java.sql.Time startedTime;
}
在Java代碼中,這將是實現它的方法。
Subject subject = new Subject();
Time startedTime = Time.valueOf("HH:MM:SS");
subject.setStartedTime(startedTime);
但現在我需要做同樣的注射是通過XML Time
對象在Subject
豆
<bean id="startedTime" class="mx.com.project.Subject">
<property name="startedTime">
<!-- java.sql.Time injection-->
</property>
</bean>
我一直在尋找在互聯網上一段時間,但還沒有找到任何例子這個。只要一通過格式化字符串"yyyy-MM-dd"
轉換爲使用SimpleDateFormat.parse("yyyy-MM-dd")
這讓我覺得應該有一個轉換到String
對象Time
類似的方式Date
對象注入Date
財產成Customer
對象。這是我發現的例子。
<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-2.5.xsd">
<bean id="dateFormat" class="java.text.SimpleDateFormat">
<constructor-arg value="yyyy-MM-dd" />
</bean>
<bean id="customer" class="com.mkyong.common.Customer">
<property name="date">
<bean factory-bean="dateFormat" factory-method="parse">
<constructor-arg value="2010-01-31" />
</bean>
</property>
</bean>
</beans>
順便說一句,the link to the above example
這似乎是另一種有效的方式來做到這一點。感謝您的回答 – Sandoval0992