Skip to content

Commit a023966

Browse files
author
Claus Nielsen
committed
Bitcoin host, username and password can now be overridden in bitcoind-client-test.properties.
1 parent 7d559f8 commit a023966

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

src/main/java/dk/clanie/bitcoin/client/BitcoindClientDefaultConfig.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
import org.springframework.beans.factory.annotation.Value;
2727
import org.springframework.context.annotation.Bean;
2828
import org.springframework.context.annotation.Configuration;
29-
import org.springframework.context.annotation.PropertySource;
30-
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
29+
import org.springframework.context.annotation.ImportResource;
3130
import org.springframework.http.client.ClientHttpRequestFactory;
3231
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
3332
import org.springframework.web.client.ResponseErrorHandler;
@@ -36,8 +35,10 @@
3635
/**
3736
* Default BitcoindClient configuration.
3837
* <p>
39-
* Loads bitcoind-client.properties from the classpath. It must define the
40-
* following properties:
38+
* Loads properties from bitcoind-client.properties and/or
39+
* bitcoind-client-test.properties, one of which should be present on the
40+
* classpath and define the following properties:
41+
*
4142
* <pre>
4243
* <code>
4344
* bitcoind.client.host = localhost
@@ -47,10 +48,13 @@
4748
* </code>
4849
* </pre>
4950
*
51+
* If both property files are present on the classpath, settings in
52+
* bitcoind-client-test.properties takes precedence.
53+
*
5054
* @author Claus Nielsen
5155
*/
5256
@Configuration
53-
@PropertySource("classpath:/bitcoind-client.properties")
57+
@ImportResource("classpath:/META-INF/spring/bitcoind-client-context.xml")
5458
public class BitcoindClientDefaultConfig {
5559

5660
@Value("${bitcoind.client.host}")
@@ -65,13 +69,15 @@ public class BitcoindClientDefaultConfig {
6569
@Value("${bitcoind.client.password}")
6670
private String password;
6771

72+
6873
@Bean
6974
public BitcoindClient bitcoindClient() {
7075
BitcoindClient bitcoindClient = new BitcoindClient();
7176
bitcoindClient.setUrl("http://" + host + ":" + port);
7277
return bitcoindClient;
7378
}
7479

80+
7581
@Bean
7682
public RestTemplate restTemplate() {
7783
RestTemplate restTemplate = new RestTemplate();
@@ -80,20 +86,24 @@ public RestTemplate restTemplate() {
8086
return restTemplate;
8187
}
8288

89+
8390
private ResponseErrorHandler errorHandler() {
8491
return new BitcoindJsonRpcErrorHandler();
8592
}
8693

94+
8795
private ClientHttpRequestFactory requestFactory() {
8896
return new HttpComponentsClientHttpRequestFactory(httpClient());
8997
}
9098

99+
91100
private HttpClient httpClient() {
92101
DefaultHttpClient httpClient = new DefaultHttpClient();
93102
httpClient.setCredentialsProvider(credentialsProvicer());
94103
return httpClient;
95104
}
96105

106+
97107
private CredentialsProvider credentialsProvicer() {
98108
CredentialsProvider credsProvider = new BasicCredentialsProvider();
99109
credsProvider.setCredentials(
@@ -102,9 +112,5 @@ private CredentialsProvider credentialsProvicer() {
102112
return credsProvider;
103113
}
104114

105-
@Bean
106-
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
107-
return new PropertySourcesPlaceholderConfigurer();
108-
}
109115

110116
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
5+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
6+
7+
<context:annotation-config />
8+
9+
<context:property-placeholder
10+
location="classpath:/bitcoind-client.properties, classpath:/bitcoind-client-test.properties"
11+
ignore-resource-not-found="true" />
12+
13+
</beans>

0 commit comments

Comments
 (0)