Reputation: 33
getting an error in beans.xml
, please see this error.
I'm making a simple program in Spring, i'm completely beginner, I have two files.
But in beans.xml
, it shows an error in <property name="name" //here is an error.. value="Hello World" />
It says:
Attribute : name The name of the property, following JavaBean naming conventions.
Data Type : string
here is my full codes:
<?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.xsd">
<bean id="helloworld" class="sample1.HelloWorld">
<property name="message" value="Hello World!!.."/>
</bean>
</beans>
As i said previously, i have tow files one contain HelloWorld.java
:
package sample1;
public class HelloWorld {
public String message;
public void setMessage(){
this.message=message;
}
public void getMessage(){
System.out.println("Your message: "+message);
}
}
And second contain MainProgram.java
:
package sample1;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MainProgram {
public static void main(String[] args){
ApplicationContext context=new ClassPathXmlApplicationContext("Beans.xml");
HelloWorld hw=(HelloWorld)context.getBean("helloworld");
hw.getMessage();
}
}
Help would be appreciated!
Upvotes: 3
Views: 4917
Reputation: 46841
As per Java Beans specification it's not a valid setter method.
It should be
public void setMessage(String message){
this.message=message;
}
Upvotes: 3