spring - SpringBoot and SpringBatch having issues trying to register a Bean e.g. error while injecting -


my scenario is: there old application highly depends on org.w3c.dom.element , org.apache.xerces.dom.documentimpl.

this application reads spreadsheet customer, reads many local xml files parameters, , depending on each node value, creates new file. in other words, there many rules applied according each node value , must hold them new application.

my requirement is: have create rest web service receive spreadsheet , process same rules. decided use spring batch , spring boot, thought first time both.

everything going right till tried inject org.w3c.dom.element. read manual must missing fundamental concept:

http://docs.spring.io/spring-boot/docs/current-snapshot/reference/htmlsingle/#using-boot-importing-xml-configuration http://docs.spring.io/spring-boot/docs/current/reference/html/howto-spring-boot-application.html 

the error:

2015-07-17 05:34:58.405  info 15348 --- [           main] hello.batchconfiguration                 :  2015-07-17 05:34:58.425  warn 15348 --- [           main] ationconfigembeddedwebapplicationcontext : exception encountered during context initialization - cancelling refresh attempt org.springframework.beans.factory.beancreationexception: error creating bean name 'batchcontroller': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire field: org.springframework.batch.core.job hello.batchcontroller.job; nested exception org.springframework.beans.factory.unsatisfieddependencyexception: error creating bean name 'importuserjob' defined in class path resource [hello/batchconfiguration.class]: unsatisfied dependency expressed through constructor argument index 1 of type [org.springframework.batch.core.step]: : error creating bean name 'step1' defined in class path resource [hello/batchconfiguration.class]: unsatisfied dependency expressed through constructor argument index 3 of type [org.springframework.batch.item.itemprocessor]: : error creating bean name 'processor': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire field: private org.w3c.dom.element hello.messageitemprocessor.element; nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [org.w3c.dom.element] found dependency: expected @ least 1 bean qualifies autowire candidate dependency. dependency annotations: candidate dependency. dependency annotations:  

my code:

import org.springframework.beans.factory.annotation.autowired; import org.w3c.dom.*; public class messageitemprocessor implements itemprocessor<message, message> {        private static final logger log = loggerfactory.getlogger(messageitemprocessor.class);        @autowired        private element element;     @override     public message process(final message message) throws exception {        log.info("processing");        return message;     } } 

application.java

@configuration @componentscan @enableautoconfiguration @importresource({"classpath*:applicationcontext.xml"}) //i tried see happens public class application {     public static void main(string[] args) {         applicationcontext ctx = springapplication.run(application.class, args);         string[] beannames = ctx.getbeandefinitionnames();         arrays.sort(beannames);         (string beanname : beannames) {             system.out.println(beanname);          }     } } 

from on, in fact, there tentatives. not expecting necessary add applicationcontext.xml, nor dispatcher-servelet neither web.xml tried see if gave me light. applicationcontext.xml because understood boot take care of context initialization. way, tried.

first tried add applicationcontext.xml in classpath , @importresource

applicationcontext.xml ...

       <bean id="element" class="org.w3c.dom.element" /> </beans> 

second tried use dispatcher-servlet been pointed in config.xml mvc-dispatcher-servlet.xml ...

<bean id="element" class="org.w3c.dom.element" /> </beans> 

web.xml

       <display-name>test</display-name>        <servlet>               <servlet-name>mvc-dispatcher</servlet-name>               <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class>               <load-on-startup>1</load-on-startup>        </servlet>        <servlet-mapping>               <servlet-name>mvc-dispatcher</servlet-name>               <url-pattern>/</url-pattern>        </servlet-mapping>        <context-param>               <param-name>contextconfiglocation</param-name>               <param-value>/applicationcontext.xml</param-value>        </context-param>        <listener>               <listener-class>org.springframework.web.context.contextloaderlistener</listener-class>        </listener> </web-app> 


Comments