Skip to content
Advertisement

Spring autowiring dependency with constructor arguments

I have created a service class, TestService whose constructor takes an array of Strings and has a little logic to return a list of Strings with length greater than 5.

How do I get about injecting this into my Controller class with the array of Strings argument?

JavaScript

Advertisement

Answer

I think it is impossible. Instead inject String[] testStrings holder:

JavaScript
JavaScript
JavaScript

However, in this example, it seems better to just pass testStrings as getStringsOverLength5 method argument.

Advertisement