I'm getting null values for some of the methods in pojo class and other methods are working fine. This is my POJO class Student.java
public class Student {
private int id;
private String name;
private String message1;
private String message2;
private String message3;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void init()
{
System.out.println("Bean is started");
}
public void destroy()
{
System.out.println("Bean is destroyed");
}
public String getMessage1() {
return message1;
}
public void setMessage1(String message1) {
this.message1 = message1;
}
public String getMessage2() {
return message2;
}
public void setMessage2(String message2) {
this.message2 = message2;
}
public String getMessage3() {
return message3;
}
public void setMessage3(String message3) {
this.message3 = message3;
}
}
This is my xml file, beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="student" class="Student">
<property name="id" value="2342"></property>
<property name="name" value="RamaKrishna"></property>
<property name="message1" value="Student--message1"></property>
<property name="message3" value="Student--message3"></property>
</bean>
</beans>
This is my main method logic, Logic.java
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Logic{
public static void main(String args[]){
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
Student student = (Student)context.getBean("student");
System.out.println(student.getId());
System.out.println(student.getName());
System.out.println(student.getMessage1());
System.out.println(student.getMessage3());
}
}
I'm getting output null values for the 3rd and 4th print statements. My output is :
2342
RamaKrishna
null
null
I supposed to get output like
2342
RamaKrishna
Student--message1
Student--message3
Please help to understand why it is giving like this.