Hello, I'm attempting to change Java 8 code to Kot...
# spring
m
Hello, I'm attempting to change Java 8 code to Kotlin, which includes changing field-based injection to constructor-based injection, but Spring is throwing me errors about missing default constructors. This isn't exactly a problem Kotlin specifically because it also fails when trying in Java, but maybe there's a trick to it that someone here knows. (Spring 4.2.6, Spring Boot 1.3.5)
n
@minus : are the constructor based injections annotated with
@Autowired
m
in kotlin yes, in java it complained that @Autowired wasn't allowed with parameters
a
did you added the
constructor
keyword as explained here https://kotlinlang.org/docs/reference/annotations.html#usage ?
m
ah yep, putting the annotation on the constructor instead of with the args (no compiler error on kotlin?) makes it work, thanks, @agomez @nayanjyoti
n
@Autowired
on constructors is not required since latest versions of Spring try without 🙂
n
@nfrankel it will require an upgrade to spring 4.3
@minus is using (Spring 4.2.6, Spring Boot 1.3.5)
n
@nerses ok