title: Creating a Couchbase configuration class in Spring Boot, using data form application.properties?
body: <p>starting to use Couchbase Java SDK with spring boot, to access the cluster, bucket and collection (sdk 3.+) I created a <code>@Configuration</code> class as follows:</p>
  <pre><code>@Configuration
  public class Database {
  
  Cluster cluster = Cluster.connect(&quot;localhost&quot;, &quot;Administrator&quot;, &quot;password&quot;);
  Bucket bucket = cluster.bucket(&quot;blackbox&quot;);
  
  @Bean
  public Collection collection() {
      return this.bucket.defaultCollection();
  }
  
  @Bean
  public Bucket bucket() {
      return this.bucket;
  }
  
  @Bean
  public Cluster cluster() {
      return this.cluster;
  }
  </code></pre>
  <p>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 <code>@Value</code> 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?</p>
  <p>Here's how tried creating the bean Cluster using <code>@Value</code>:</p>
  <pre><code>@Bean
  public Cluster cluster(@Value(&quot;${host}&quot; String host,@Value(&quot;${user}&quot; String user,
  @Value(&quot;${pass}&quot; String pass) {
      return Cluster.connect(host,user,pass);
  }
  </code></pre>