Constretto is built with maven, so if you are using maven, you can simply add Constretto as dependencies in your pom:
<dependencies>
...
<dependency>
<groupId>org.constretto</groupId>
<artifactId>constretto-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.constretto</groupId>
<artifactId>constretto-core</artifactId>
<version>1.1</version>
<scope>runtime</scope>
</dependency>
...
</dependencies>
If you would like to use the Constretto Junit support with junit 4.4 (spring 2.5.x) add:
<dependency>
<groupId>org.constretto</groupId>
<artifactId>constretto-test</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
If you would like to use the Constretto Junit support with junit 4.5 (spring 3.x) add:
<dependency>
<groupId>org.constretto</groupId>
<artifactId>constretto-test-junit-4.5</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
These artifacts are currently not published to the main maven repository, so in order to download them add the following
repository definition in your pom:
<repositories>
<repository>
<id>constretto.org</id>
<name>Constretto public maven repository</name>
<url>http://repo.constretto.org/content/repositories/releases</url>
</repository>
</repositories>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:constretto="http://constretto.org/schema/constretto" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://constretto.org/schema/constretto http://constretto.org/schema/constretto/constretto-1.2.xsd"> <constretto:configuration> <constretto:stores> <constretto:properties-store> <constretto:resource location="classpath:properties/test1.properties"/> </constretto:properties-store> </constretto:stores> </constretto:configuration> </beans>
ConstrettoConfiguration config =
new ConstrettoBuilder()
.createPropertiesStore()
.addResource(new DefaultResourceLoader().getResource("classpath:test1.properties"))
.done()
.getConfiguration();
public class DataSourceConfiguration {
private String myUrl;
private String myPassword;
@Configure
public void configure(String url, @Configuration(expression = "password") String secret) {
this.myUrl = url;
this.myPassword = secret;
}
public String getUrl() {
return myUrl;
}
public String getPassword() {
return myPassword;
}
}
public class MyApp{
public static void main(String[] args){
ConstrettoConfiguration configuration = buildConfig();
MyConfiguredClass myConfiguredClass = new MyConfiguredClass();
configuration.on(myConfiguredClass);
}
}
key1 = default value for key1
key2 = default value for key2
@some tag.key1 = value in tag "some tag" for key1
@some tag.key2 = value in tag "some tag" for key2
java -jar myapp.jar MyMain -DCONSTRETTO_TAGS=development,linux,mock, some tag
or :
export CONSTRETTO_TAGS=development,linux,mock, some tag
java -jar myapp.jar MyMain