https://kotlinlang.org logo
#spring
Title
s

soudmaijer

10/02/2017, 5:57 PM
@villela do you have a code sample of the part that is failing
v

villela

10/02/2017, 6:04 PM
Copy code
@RestController
open class SomeController(val aRepository: SomeRepository) {
	@Cacheable("my.json")
    @GetMapping("/", produces = ["application/json"])]
    fun list(): List<SomeClass> = aRepository.findAll()
}
in the generated controller object object, ...EnhancerBySpringGCLIB, "aRepository" is null
when I call list()
before, without @EnableCaching in the app configuration, aRepository is injected correctly
if I change the inject method to use @Autowired/lateinit it also doesn't work, complaining that the property could not be initialized
s

soudmaijer

10/02/2017, 7:03 PM
have you tried
Copy code
open fun list()
You are using kotlin 1.2-beta? same results with 1.1.51?
v

villela

10/02/2017, 7:45 PM
nice catch
the problem was indeed the final function, for some reason the proxy also needs it open
if the class isn't open complains while starting spring, but not if the function isn't, but if it is it doesn't work as expected
thanks!
c

Czar

10/03/2017, 8:36 AM
If you check the spring startup log you should see a warning regarding method not being open.
👍 1
s

soudmaijer

10/03/2017, 11:15 AM
@villela this only happens when you run the main from your app. When you use gradle or maven you can configure the allopen plugin. With maven if run the app using mvn spring-boot:run command it will not cause these ‘issues’
👍 1
3 Views