Thread: Constructor confusion

Forum : Spring Core and Aspect Oriented Programming (AOP).   24 Jul, 2017 23:47
User Image
sushil4699

Newbie

Joined: 21 Apr, 2017

Points: 100

Threads: 5

Posts: 0

Constructor confusion

| Quote Date : 24 Jul, 2017    Views:1012    

Question-->  @ConstructorProperties annotation is not working in below example why ?

Machine.java
--------------
package com.alex.beans;

import java.beans.ConstructorProperties;

public class Machine {
private int id;
    private String name;
    private long serialNumber;
    @ConstructorProperties({"machineid","machinename","machineserialNumber"})
public Machine(int machineid, String machinename, long machineserialNumber) {
super();
this.id = machineid;
this.name = machinename;
this.serialNumber = machineserialNumber;
}
@Override
public String toString() {
return "Machine [id=" + id + ", name=" + name + ", serialNumber=" + serialNumber + "]";
}
   
}


Test.java
----------
package com.alex.test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import com.alex.beans.Machine;
public class Test{

public static void main(String[] args) {
BeanFactory factory=new XmlBeanFactory(new ClassPathResource("com/alex/commons/application-Context.xml"));
Machine machine=(Machine) factory.getBean("machine",Machine.class);
        System.out.println(machine);

}

}

application-Context.xml
-----------------------------

<?xml version="1.0" encoding="UTF-8"?>
<bean id="machine" class="com.alex.beans.Machine">
<constructor-arg name="machineid" value="41" />
<constructor-arg name="machineserialNumber" value="55" />
<constructor-arg name="machinename" value="sanjeev" />
</bean>
</beans>




Comments

User Image
Ashok1207

Newbie

Joined : 20 Apr, 2017

Points : 145

Threads: 9

Posts: 61

Re: Constructor confusion

Reply Date : 5 Dec, 2018

Executed same piece of code using 4.3.9 version jars it was successful.Please let us know what is the issue you are facing.

Load More

No More Comments