Getting error in beans.xml

getting error in beans.xml

, see this error .

I am doing a simple program in Spring, I am completely newbie, 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 the convention JavaBean name.

Data type: string

here are my complete 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 before, I have tow files containing 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 the second contains 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!

+3


source to share


1 answer


This is not a valid install method as per the Java Beans specification.

It should be



public void setMessage(String message){
    this.message=message;
}

      

+3


source







All Articles