Results 1 to 4 of 4

Thread: Wiring a JDK class

  1. #1
    Join Date
    Jun 2008
    Posts
    2

    Default 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. #2
    Join Date
    May 2005
    Location
    San Diego, CA
    Posts
    76

    Default

    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" />

  3. #3
    Join Date
    Jun 2008
    Posts
    2

    Thumbs up

    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 )

  4. #4
    Join Date
    May 2005
    Location
    San Diego, CA
    Posts
    76

    Default

    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>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •