I don't understand... I actually defined constructor but I am getting
No constructor with 0 arguments defined in class
@Component public class CustomMessageSource extends ReloadableResourceBundleMessageSource { public CustomMessageSource(Locale locale){ this.propertiesHolder = getMergedProperties(locale); this.properties = propertiesHolder.getProperties(); } //... other setting, getters This is how I instantiated it
CustomMessageSource customMessage = new CustomMessageSource(locale);
This is my stack trace
Caused by: java.lang.NoSuchMethodException: com.app.service.CustomMessageSource.<init>() at java.lang.Class.getConstructor0(Class.java:3074) at java.lang.Class.getDeclaredConstructor(Class.java:2170) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:80) ... 38 more
1argument, not0. If you want an0argument constructor and you defined at least one constructor, you need to write a0argument constructor yourself. Java will provide a0argument constructor (default-constructor), if and only if you did not write any constructor at all.CustomMessageSourceinstance with a consistent state guaranteed by the constructor with arg that is defined.@Autowiredon the constructor (or use Spring 4.3) to tell spring which one to use, else it expects a default no-args constructor.