简体   繁体   English

在beans.xml中获取错误

[英]Getting an error in beans.xml

getting an error in beans.xml , please see this error . beans.xml收到错误,请看到此错误

I'm making a simple program in Spring, i'm completely beginner, I have two files. 我在Spring做一个简单的程序,我是初学者,我有两个文件。

But in beans.xml , it shows an error in <property name="name" //here is an error.. value="Hello World" /> 但是在beans.xml ,它在<property name="name" //here is an error.. value="Hello World" />显示错误<property name="name" //here is an error.. value="Hello World" />

It says: 它说:

Attribute : name The name of the property, following JavaBean naming conventions. 属性:name遵循JavaBean命名约定的属性的名称。

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 : 正如我之前所说,我有两个包含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 : 第二个包含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! 帮助将不胜感激!

As per Java Beans specification it's not a valid setter method. 根据Java Beans规范,它不是有效的setter方法。

It should be 它应该是

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM