我做我的第一個進軍春,我收到以下錯誤嘗試在Eclipse中運行:春聲稱相同的類名是不同的
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'model' must be of type [com.myCompany.project.Model], but was actually of type [com.myCompany.project.Model]
代碼導致異常:
import com.myCompany.project.Model;
// some code
public Model getModel() {
ClassPathXmlApplicationContext applicationContext =
new ClassPathXmlApplicationContext("client-context.xml");
return applicationContext.getBean("model", Model.class);
}
Spring 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"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config />
<bean id="model" class="com.myCompany.project.Model" />
</beans>
client-context.xml位於項目/資源中,代碼i n project/src/main/
我認爲這是一個類路徑問題,但我不知道如何解決它。
您的spring xml文件的類名中的小寫'model'是否爲拼寫錯誤? – 2013-03-19 13:21:45