アノテーションを使用してSpringControllerのmessages.propertiesファイルからプロパティにアクセスする方法。
例を挙げてください。
アノテーションを使用してSpringControllerのmessages.propertiesファイルからプロパティにアクセスする方法。
例を挙げてください。
以下はdispatcher-servlet.xmlです
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring- context.xsd ">
<context:annotation-config/>
<util:properties id="messageProperties" location="/messages.properties"/></beans></pre>
そして、あなたがコントローラーについて述べたように、私は自分のプロパティで同じコードを使用しています。@Value アノテーションを解決できません。
まず、以下のように、dispatcher-servlet.xml ファイルでプロパティ プレース ホルダーを定義する必要があります。
<util:properties id="messageProperties" location="/messages.properties"/>
messages.properties ファイルのパスを変更する必要があります。
そして、@Value
アノテーションを使用してプロパティファイルの値にアクセスできます。
private @Value("#{messageProperties['your.message.code']}") String message;
これがお役に立てば幸いです。乾杯。