Announcement Announcement Module
Collapse
No announcement yet.
Wiring a JDK class Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Wiring a JDK class

    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.

  • #2
    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" />

    Comment


    • #3
      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 )

      Comment


      • #4
        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>

        Comment

        Working...
        X