Thread: Constructor confusion

Forum : Spring Core and Aspect Oriented Programming (AOP).   24-7-2017 11:47:59 PM
User Image
sushil4699

Newbie

Joined: Apr 21, 2017

Points: 100

Threads: 5

Posts: 0

Constructor confusion

| Quote Date : Jul 24, 2017    Views:875    

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 : Apr 20, 2017

Points : 145

Threads: 9

Posts: 60

Re: Constructor confusion

Reply Date : Dec 5, 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