我在Spring中傳遞一個整數時出錯。錯誤在一個bean中傳遞一個值
<bean id="propConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/application.properties"/>
</bean>
<bean id="portListenerService" class="com.service.portListenerService" scope="prototype" lazy-init="true" parent="abstractService">
<property name="devicePort" value="${devicePort}"/>
</bean>
portListenerService.java:
@Required
public final void setDevicePort(Integer devicePort) {
this.devicePort= devicePort;
}
這是這樣做的正確方法?因爲我得到一個錯誤:即使我硬編碼端口,而不是從application.properties
拉的
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'portListenerService' defined in ServletContext resource [/WEB-INF/service-config.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [int] for property 'devicePort'; nested exception is java.lang.IllegalArgumentException: Original must not be null
,我得到了同樣的錯誤。還有其他一些問題嗎?
錯誤消息提到「原始不能爲空」。這難道不是一個謎嗎? – 2011-03-24 17:33:50
你的屬性文件是否有一個名爲'devicePort'的屬性?通過「硬代碼」我假設你的意思是'價值=「1234」'? – Jeremy 2011-03-24 18:03:33
也許這是一個愚蠢的評論,但我注意到你的bean'portListenerService'有一個'parent =「abstractService」':AFAIK子bean類必須與父類兼容,即它必須接受父類的屬性值。您的'abstractService'是否接受'devicePort'的Integer? – MarcoS 2011-03-25 12:14:52