spring

Property Source

Annotation

Sample property file : nexus.properties

Sample property file content:

nexus.user=admin
nexus.pass=admin
nexus.rest.uri=https://xxx.xxx.xxx.xxx:xxxx/nexus/service/local/artifact/maven/content

Sample Context File xml configuration

<context:property-placeholder location="classpath:ReleaseBundle.properties" />

Sample Property Bean using annotations

@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;
}

Sample Constant class

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="";
}

Sample xml configuration using PropertyPlaceholderConfigurer

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
     <list>
           <value>classpath:ReleaseBundle.properties</value>
     </list>
</bean>

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow