- Build and publish micronaut lib with an
EachProperty
cd each-property
./gradlew publishToMavenLocal
TestConfiguration class:
@EachProperty("test.data")
@ToString(includeNames = true, includePackage = false)
class TestConfiguration {
private final String name
String prop
TestConfiguration(@Parameter String name) {
this.name = name
}
}
TestService class:
@Singleton
class TestService {
private final ApplicationContext applicationContext
TestService(ApplicationContext applicationContext) {
this.applicationContext = applicationContext
}
Collection<TestConfiguration> getTestConfigurations() {
applicationContext.getBeansOfType(TestConfiguration)
}
}
- Run grails project
cd grails
./grailsw run
- Call Test Controller
curl http://localhost:8080/test
TestController class:
class TestController {
static responseFormats = ['json']
@Autowired
TestService testService
def index() {
def configurations = testService.testConfigurations
render([result: configurations.size()] as JSON)
}
}
Expected:
result (configurations
) should be 2 as application.yml
contains:
test:
data:
a:
prop: a
b:
prop: b
Actually:
result (configurations
) is 0