Spring constructor injection without configuration (annotations, XML, java config) -
i have problem constructor injection component scanned beans. have following service
public class someservice implements isomeservice { private isomeservice2 someservice2; public someservice(isomeservice2 someservice2) { this.someservice2 = someservice2; } . . . }
then have configuration perform component scanning:
@configuration @componentscan( basepackages = "base.backage", includefilters = @componentscan.filter(type = filtertype.regex, pattern = ".*")) public class appconfig { }
then try resolve isomeservice:
applicationcontext ctx = new annotationconfigapplicationcontext(appconfig.class); isomeservice someservice1 = ctx.getbean(isomeservice.class);
this throws exception java.lang.nosuchmethodexception (it not have default non arg constructor). have isomeservice2 bean scanned , registered well. can fix adding @autowired annotation someservice constructor.
is there way how make constructor injection default without use of annotations inside classes, xml or explicit configuration on particular bean?
Comments
Post a Comment