How can I pass a value from application.properties in @Scope and @Collection annotations?

Viewed 27

I want to prepare for a migration from Couchbase 6.X to 7.X. For this, I want to configure the scope and collection for my cluster. In the documentation of spring-data-couchbase, I saw that I just need to add @Scope and @Collection on my repository. This configuration works:

package xxx.couchbase;

import xxx.MyDocument;
import org.springframework.data.couchbase.repository.Collection;
import org.springframework.data.couchbase.repository.CouchbaseRepository;
import org.springframework.data.couchbase.repository.Scope;
import org.springframework.stereotype.Repository;

@Repository
@Scope("_default")
@Collection("_default")
public interface MyDocumentRepository extends CouchbaseRepository<MyDocument, String> {
}

What I want to do:

package xxx.couchbase;

import xxx.MyDocument;
import org.springframework.data.couchbase.repository.Collection;
import org.springframework.data.couchbase.repository.CouchbaseRepository;
import org.springframework.data.couchbase.repository.Scope;
import org.springframework.stereotype.Repository;

@Repository
@Scope("${couchbase.scope}")
@Collection("${couchbase.collection}")
public interface MyDocumentRepository extends CouchbaseRepository<MyDocument, String> {
}

application.properties:

couchbase.scope=_default
couchbase.collection=_default

This latter configuration doesn't work, because the string value in the annotation is not parsed and is taken literally. I'm working with Spring Boot version 2.7.3, spring-boot-starter-data-couchbase version 2.7.3.

Is there another way to pass the value from the application.properties to the annotations ?

0 Answers
Related