Spring 3 にアップグレードする前に、applicationContext.xml ファイルに次のように記述しました。
<bean class="com.northgateis.pole.ws.PolePayloadValidatingInterceptor">
<property name="validateRequest" value="${validateRequest}" />
<property name="validateResponse" value="${validateResponse}" />
</bean>
${validateRequest) および ${validateRequest) は、プロパティ ファイルで定義されている場合と定義されていない場合があるプロパティを参照します。
Spring 2 では、これらのプロパティがプロパティ ファイルに存在しない場合、Bean のセッターが呼び出されなかったため、PolePayloadValidatingInterceptor でハードコーディングされたデフォルトが使用されました。
Spring 3 にアップグレードした後、動作が異なるようです。プロパティ ファイルにプロパティが存在しない場合、次の例外が発生します。
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'annotationMapping' defined in class path resource [com/northgateis/pole/ws/applicationContext-ws.xml]: Could not resolve placeholder 'validateRequest'
at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:272)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:75)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:640)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:615)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:405)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:272)
私はSpring ELを試してみましたが、以下はうまくいかないようです:
<bean class="com.northgateis.pole.ws.PolePayloadValidatingInterceptor">
<property name="validateRequest" value="${validateRequest?:true}" />
<property name="validateResponse" value="${validateResponse?:false}" />
</bean>
プロパティがプロパティ ファイルで定義されている場合でも、Elvis 演算子の後の値が常に使用されます。構文が受け入れられるのは興味深いことです。
助言がありますか?