26
26
import org .springframework .beans .factory .annotation .Value ;
27
27
import org .springframework .context .annotation .Bean ;
28
28
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 ;
31
30
import org .springframework .http .client .ClientHttpRequestFactory ;
32
31
import org .springframework .http .client .HttpComponentsClientHttpRequestFactory ;
33
32
import org .springframework .web .client .ResponseErrorHandler ;
36
35
/**
37
36
* Default BitcoindClient configuration.
38
37
* <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
+ *
41
42
* <pre>
42
43
* <code>
43
44
* bitcoind.client.host = localhost
47
48
* </code>
48
49
* </pre>
49
50
*
51
+ * If both property files are present on the classpath, settings in
52
+ * bitcoind-client-test.properties takes precedence.
53
+ *
50
54
* @author Claus Nielsen
51
55
*/
52
56
@ Configuration
53
- @ PropertySource ("classpath:/bitcoind-client.properties " )
57
+ @ ImportResource ("classpath:/META-INF/spring/ bitcoind-client-context.xml " )
54
58
public class BitcoindClientDefaultConfig {
55
59
56
60
@ Value ("${bitcoind.client.host}" )
@@ -65,13 +69,15 @@ public class BitcoindClientDefaultConfig {
65
69
@ Value ("${bitcoind.client.password}" )
66
70
private String password ;
67
71
72
+
68
73
@ Bean
69
74
public BitcoindClient bitcoindClient () {
70
75
BitcoindClient bitcoindClient = new BitcoindClient ();
71
76
bitcoindClient .setUrl ("http://" + host + ":" + port );
72
77
return bitcoindClient ;
73
78
}
74
79
80
+
75
81
@ Bean
76
82
public RestTemplate restTemplate () {
77
83
RestTemplate restTemplate = new RestTemplate ();
@@ -80,20 +86,24 @@ public RestTemplate restTemplate() {
80
86
return restTemplate ;
81
87
}
82
88
89
+
83
90
private ResponseErrorHandler errorHandler () {
84
91
return new BitcoindJsonRpcErrorHandler ();
85
92
}
86
93
94
+
87
95
private ClientHttpRequestFactory requestFactory () {
88
96
return new HttpComponentsClientHttpRequestFactory (httpClient ());
89
97
}
90
98
99
+
91
100
private HttpClient httpClient () {
92
101
DefaultHttpClient httpClient = new DefaultHttpClient ();
93
102
httpClient .setCredentialsProvider (credentialsProvicer ());
94
103
return httpClient ;
95
104
}
96
105
106
+
97
107
private CredentialsProvider credentialsProvicer () {
98
108
CredentialsProvider credsProvider = new BasicCredentialsProvider ();
99
109
credsProvider .setCredentials (
@@ -102,9 +112,5 @@ private CredentialsProvider credentialsProvicer() {
102
112
return credsProvider ;
103
113
}
104
114
105
- @ Bean
106
- public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer () {
107
- return new PropertySourcesPlaceholderConfigurer ();
108
- }
109
115
110
116
}
0 commit comments