Hi,
I read about Spring few days ago and I'm very excited about it, but somewhat confused as well. I was thinking whether it's possible to use Spring to wire a "non-bean" class, say java.util.Date, in a bean.
Printable View
Hi,
I read about Spring few days ago and I'm very excited about it, but somewhat confused as well. I was thinking whether it's possible to use Spring to wire a "non-bean" class, say java.util.Date, in a bean.
yes you can. This will create a date object with the current time when the application context comes up:
Code:<bean id="myDate" class="java.util.Date" />
Thanks for the reply, umeshajb. Taking this one step further, what if one needs a Date object wired with non-default value - since this class does not follow Java Beans naming conventions I can't figure this out, maybe it's a limitation of the framework (or of my knowledge of the framework :rolleyes:)
You should read this section in the spring documentation http://static.springframework.org/sp...ctor-injection. What you would do if you want to use the non-deprecated constructor in java.util.Date and set the time to 1000 milliseconds since epoch is
Code:<bean id="myDate" class="java.util.Date">
<constructor-arg type="long" value="1000"/>
</bean>