1
我有這個錯誤,而試圖依賴注入Spring框架的bean類[人]的無效的屬性bean類的 'messageService'[人] - Spring框架
無效屬性 'messageService':豆 屬性'messageService'不可寫或具有無效設置器 方法。你的意思是'messageService'嗎?
這裏是我的類人:
public class Person {
private MessageService messageService;
public void setMessageService(MessageService messageService){
this.messageService = messageService;
}
public MessageService getMessageService() {
return this.messageService;
}
public void Chao(String Subject, String Message)
{
messageService.sendMessage(Subject,Message);
}
}
這裏是我的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.xsd">
<bean id="email" class="Email"></bean>
<bean id="Person" class="Person">
<property name="messageService " ref="email"></property>
</bean>
</beans>
最後Main類
public class Main {
public static void main(String args[]) throws Exception{
ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
Person test = (Person) context.getBean("Person");
test.Chao("abc","abc");
}
}
MessageService
是一個接口,Email implements MessageService
類 任何人都可以告訴我我做錯了什麼嗎?非常感謝
我很抱歉我的疏忽,謝謝先生! –