I was wondering if in Micronaut it is possible to achieve similar functionality like in Sppring where by creating custom annotation we are able to populate custom properties into the application context (environment). I have working example in Spring but can’t figure out if and how correctly could be achieved.
Spring:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@TestPropertySource
public @interface EnableSqS {
/**
* Syntax: {property-to-be-set={queue-name}}
* example:
* "create-queues:sqs-queue-url=test-queue"
* this creates queue `test-queue` on application start up
* under property 'sqs-queue-url'
* @return
*/
@AliasFor(annotation = TestPropertySource.class, attribute = "properties")
String[] createQueues();
}
I implemented similar thing in Micronaut:
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
@PropertySource
annotation class EnableSqs(
@get:AliasFor(annotation = PropertySource::class, member = "value")
vararg val createQueues: String = []
)
but when running simple test to validate:
@EnableSqs(createQueues = ["create-queues:test-sqs-url:test-queue"])
internal class TestScnerio {
}
@Factory
internal class SqsQueueFactory(
private val environment: Environment,
) {
private val logger = KotlinLogging.logger {}
@Context
@Singleton
fun createQueues() = runBlocking {
logger.info { environment.getProperties("create-queues") }
}
}
There is no such property registered in the application context. Any idea if this could actually be achievable?