java-在beans.xml中获取错误
作者:互联网
在beans.xml中遇到错误,请参阅此error.
我在Spring中编写了一个简单的程序,我完全是新手,我有两个文件.
但是在beans.xml中,它在< property name =“ name”中显示错误// //这是错误.value =“ Hello World” />
它说:
Attribute : name The name of the property, following JavaBean naming
conventions.Data Type : string
这是我的完整代码:
<?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>
正如我之前所说,我有两个文件包含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);
}
}
第二个包含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();
}
}
帮助将不胜感激!
解决方法:
根据Java Beans规范,它不是有效的setter方法.
它应该是
public void setMessage(String message){
this.message=message;
}
标签:javabeans,xml,spring,java 来源: https://codeday.me/bug/20191121/2051612.html