java - Why are some @Enable* annotations picked up without @Configuration? -
i have following classes in different packages:
@enablewebmvc public class actuatorconfig { // empty // needed rest can hit actuator endpoints } @component // remove line? @enablebatchprocessing public class batchconfig { // empty } @component @configuration public class schedulejob { @autowired private jobbuilderfactory jobbuilder; @bean protected jobexecutionlistener schedulejoblistener() { return new schedulejoblistener(); } }
(edit: added application class)
@springbootapplication public class afxapplication { public static void main(string[] args) { springapplication.run(afxapplication.class, args); } }
the first class turns on actuator features. don't need other annotations.
however, if remove @component batchconfig noted above, boot won't start because can't find dependency on jobbuilderfactory needs in order populate @autowired schedulejob.jobbuilder.
the exception:
caused by: org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [org.springframework.batch.core.configuration.annotation.jobbuilderfactory] found dependency: expected @ least 1 bean qualifies autowire candidate dependency. dependency annotations: {@org.springframework.beans.factory.annotation.autowired(required=true)} @ org.springframework.beans.factory.support.defaultlistablebeanfactory.raisenosuchbeandefinitionexception(defaultlistablebeanfactory.java:1373) ~[spring-beans-4.2.4.release.jar:4.2.4.release] @ org.springframework.beans.factory.support.defaultlistablebeanfactory.doresolvedependency(defaultlistablebeanfactory.java:1119) ~[spring-beans-4.2.4.release.jar:4.2.4.release] @ org.springframework.beans.factory.support.defaultlistablebeanfactory.resolvedependency(defaultlistablebeanfactory.java:1014) ~[spring-beans-4.2.4.release.jar:4.2.4.release] @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject(autowiredannotationbeanpostprocessor.java:545) ~[spring-beans-4.2.4.release.jar:4.2.4.release] ... 25 common frames omitted
when @component needed , when isn't needed?
(i pulled out @enable* annotations because i'm trying run unit tests don't need features enabled, , way can specify features want enable using @componentscan(basepackageclasses).)
thanks m. deinum, have answer.
by having @enable*
, disabling @enableautoconfiguration
. exception @enablebatchprocessing
, explicitly required. (i understand so, not sure why cannot handled @enableautoconfiguration
.)
the answer combination of application class listed above, , class:
@configuration @enablebatchprocessing public class batchconfig { }
once in place, else worked.
how affect test code remain task day...
Comments
Post a Comment