starting to use Couchbase Java SDK with spring boot, to access the cluster, bucket and collection (sdk 3.+) I created a @Configuration
class as follows:
@Configuration
public class Database {
Cluster cluster = Cluster.connect("localhost", "Administrator", "password");
Bucket bucket = cluster.bucket("blackbox");
@Bean
public Collection collection() {
return this.bucket.defaultCollection();
}
@Bean
public Bucket bucket() {
return this.bucket;
}
@Bean
public Cluster cluster() {
return this.cluster;
}
Thing is that I was required to use data from application.properties file. I tried autowiring Environment to get properties without luck, and multiple ways of using @Value
that also gives me errors. Is there a way to configure my connection to the DB by getting the values from the file and having the bean cluster that I can autowire? Or is maybe my solution completely wrong?
Here's how tried creating the bean Cluster using @Value
:
@Bean
public Cluster cluster(@Value("${host}" String host,@Value("${user}" String user,
@Value("${pass}" String pass) {
return Cluster.connect(host,user,pass);
}