私はSpringに問題があります。注釈を使用してシステムプロパティをロードする必要があります。注釈を使用してSpringでSystemプロパティを読み込む方法は?
私はこのアプローチをしようとしている:
@Value("${mySystemProperty}")
private String mySystemPropertyValue;
をしかし、私はこの作るとき:
System.out.println("mySystemPropertyValue="+mySystemPropertyValue);
System.out.println("system.mySystemProperty="+System.getProperty("mySystemProperty"));
をそれが返されます。
mySystemPropertyValue=null
system.mySystemProperty=myValue
間違っているのですか?
EDIT
おかげで私はすべてしようとしているが、私はいつも見返りに、すべてのシステムプロパティのnull値を取得します。あなたのコンフィギュレーションクラスがいくつかBeanFactoryPostProcessor
含まれているようだ
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, proxyTargetClass = true)
public class SecurityContextConfig extends WebSecurityConfigurerAdapter
{
@Value("#{systemProperties['your.system.property']}")
private String property;
...
}
内
@Value
のUPDATE
シンプルなアプリ実証使い方はこれを試してみてください。http://stackoverflow.com/questions/6285978/is-there-any-syntax-like- systemproperties-environment-variable-name-to-g – rapasoft
'System.out'はどこに置かれますか? SpringのマネージドBeanまたは単に普通のものの '@ Value'もあります。 –
私は@Value( "#{systemProperties ['mySystemProperty']}")と@Value( "#{systemProperties.mySystemProperty}")の両方を試しました。 –