0
これは、春のコミュニティではよくある質問です。しかし、多くの提案や回答を参照しても、以下のプログラムを正しく動作させることができませんでした。NotWritablePropertyException - コンテキストが初期化されるとき - Spring
Spring BeanにString型のプロパティを注入する必要があります。
at java.lang.Thread.run(Thread.java:744)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'authCode' of bean class [com.test.wsg.RequestMessageTransformer]: Bean property 'authCode' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1067)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:926)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:95)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1502)
:コンテキストが初期化取得され、以下のエラーを受け取る
public class RequestMessageTransformer implements InitializingBean {
private String authCode = null;
private boolean converAndMarshal = true;
public void setConverAndMarshal(boolean converAndMarshal) {
this.converAndMarshal = converAndMarshal;
}
public boolean isConverAndMarshal() {
return converAndMarshal;
}
public void setAuthCode(String authCode) {
this.authCode = authCode;
}
public String getAuthCode() {
return authCode;
}
}
:
ここ<bean id="AzoneMessageTransformer" class="com.test.wsg.RequestMessageTransformer">
<property name="converAndMarshal" value="false" />
</bean>
<bean id="BzoneMessageTransformer" class="com.test.wsg.RequestMessageTransformer">
<property name="converAndMarshal" value="false" />
<property name="authCode" >
<value>BZ</value>
</property>
</bean>
春の豆である:ここで
はBean定義であります
私の間違いを指摘するための助けや提案は非常に感謝しています。
ありがとうございます!
このような性質のものを設定する必要があり、文字列プロパティですか? – Mahesh
@Maheshバージョン使用:4.1.4.RELEASE – Vignesh
あなたは、初期化するbeanを実装しています。ここでは、afterPropertiesSet()メソッドの実装があります。最初にコンパイルされたクラスを持つことになります – kuhajeyan