Results 1 to 2 of 2

Thread: Dependancy Injection for Date Object

  1. #1
    Join Date
    May 2012
    Posts
    1

    Default Dependancy Injection for Date Object

    Dependancy Injection for Date Object doesnt seem to work

    here's the code for the xml file

    HTML Code:
    <bean id="date" class="java.util.Date"/>
    <bean id="obj"   class="com.Person.Implementor" autowire="byName">
        <property name="username"><value>Abc</value></property>
        <property name="password"><value>password</value></property>
    </bean>
    Here's the class:

    HTML Code:
    package com.Person; 
    import java.util.Date;
    import org.springframework.beans.factory.annotation.Autowired;
    
    public class Implementor {
    
     String username; String password;
     Date date;
    
    public Date getDate() {
        return date;
    }
    
    @Autowired
    public void setDate(Date date) {
        this.date = date;
    }
    
    @Override
    public String toString() {
        return "Implementor [username=" + username + ", password=" + password
                + ", date=" + date + "]";
    }
    
    
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    
    }
    The Date reference seems to have the NULL value while printing, it works fine for custom created classes tough
    Last edited by Akash123; May 31st, 2012 at 11:59 AM.

  2. #2

    Default

    This is by Spring design. Spring does not do bean auto-wiring for "simple" properties, e.g. primitives, Strings and Date. But i don't see a good reason for you to auto-wire bean with Date type.
    Last edited by tannoy; Jun 1st, 2012 at 01:41 PM.

Tags for this Thread

Posting Permissions

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