Is there anyway in spring + kotlin do to a mixed c...
# spring
g
Is there anyway in spring + kotlin do to a mixed constructor where you have e.g.
Copy code
@Service
class MyClass(
   myService: MyService, // autowired
   helper: Helper = Helper("defaultValue") // just get default value but somebody could override this in e.g. tests
)
?
n
Usually when we want to autowire from the context but override some beans we define a @Configuration as an inner class of the test class to override beans with test versions, which is supported by Spring TestContext. If it's Spring Boot there is also @TestConfiguration which is an alternative way to do it. This is all standard Spring, nothing Kotlin specific.
t
alternatively, you could also just create a secondary constructor with just one parameter and the @Autowired annotation
k
When I try this (as in the OP's example code), it works. IntelliJ gives an error saying the default argument can't be autowired, but if I just ignore the error, nothing bad seems to happen. The application runs as expected, and the unit tests run fine. It probably isn't recommended though.