I know that it should be a piece of cake, but I just donโt get anything.
In my Spring boot application, in the application.yml file, I have an entry like:
some: constructor: property: value
And I have a Spring service (this is fake, but demonstrates the problem):
package somepackage; @Service public class DummyService { public DummyService(@Value("${some.constructor.property}") String path) {} }
The launch failed:
org.springframework.beans.factory.BeanCreationException: error creating a bean with the name "dummyService" defined in the file [... (class file) ...]: Error creating bean; nested exception org.springframework.beans.BeanInstantiationException: failed instantiate [somepackage.DummyService]: default constructor not found; The nested exception is java.lang.NoSuchMethodException: somepackage.DummyService. ()
How can I convince Spring that it should use a non-empty constructor, and it should get this constructor parameter from the YAML file? Note. I do not use XML bean configuration files or anything else, and would not want to.
source share