Announcement Announcement Module
Collapse
No announcement yet.
Dependancy Injection for Date Object Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 11:59 AM.

  • #2
    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, 01:41 PM.

    Comment

    Working...
    X