2015-05-08 79 views
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類 任何人都可以告訴我我做錯了什麼嗎?非常感謝

回答

1

name="messageService "的末尾有一個空格。請刪除它。

+0

我很抱歉我的疏忽,謝謝先生! –

相關問題