spring                
            プロパティソース
        
        
            
    サーチ…
注釈
サンプルプロパティファイル:nexus.properties
サンプルプロパティファイルの内容:
nexus.user=admin
nexus.pass=admin
nexus.rest.uri=http://xxx.xxx.xxx.xxx:xxxx/nexus/service/local/artifact/maven/content
サンプル・コンテキスト・ファイルxml構成
<context:property-placeholder location="classpath:ReleaseBundle.properties" />
アノテーションを使用したサンプルProperty Bean
@Component
@PropertySource(value = { "classpath:nexus.properties" })
public class NexusBean {
    @Value("${" + NexusConstants.NEXUS_USER + "}")
    private String user;
    @Value("${" + NexusConstants.NEXUS_PASS + "}")
    private String pass;
    @Value("${" + NexusConstants.NEXUS_REST_URI + "}")
    private String restUri;
}
サンプルのConstantクラス
public class NexusConstants {
    public static final String NexusConstants.NEXUS_USER="";
    public static final String NexusConstants.NEXUS_PASS="";
    public static final String NexusConstants.NEXUS_REST_URI="";
}
PropertyPlaceholderConfigurerを使用したxml構成のサンプル
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
     <list>
           <value>classpath:ReleaseBundle.properties</value>
     </list>
</bean>
Modified text is an extract of the original Stack Overflow Documentation
        ライセンスを受けた CC BY-SA 3.0
        所属していない Stack Overflow