9

アノテーションを使用してSpringControllerのmessages.propertiesファイルからプロパティにアクセスする方法。

例を挙げてください。

4

3 に答える 3

0

message.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 アノテーションを解決できません。

于 2013-01-11T06:14:01.940 に答える
0

まず、以下のように、dispatcher-servlet.xml ファイルでプロパティ プレース ホルダーを定義する必要があります。

<util:properties id="messageProperties" location="/messages.properties"/>

messages.properties ファイルのパスを変更する必要があります。

そして、@Valueアノテーションを使用してプロパティファイルの値にアクセスできます。

private @Value("#{messageProperties['your.message.code']}") String message;

これがお役に立てば幸いです。乾杯。

于 2013-01-10T07:52:52.477 に答える