Skip to content

Latest commit

 

History

History
84 lines (64 loc) · 1.43 KB

README.md

File metadata and controls

84 lines (64 loc) · 1.43 KB

EachProperty does not work in grails / spring

  1. 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)
    }
}
  1. Run grails project
cd grails
./grailsw run
  1. 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