Java Spring Scheduled job not working -
i have web application supposed run scheduled code:
package com.myproject.daemon.jobs; import org.slf4j.logger; import org.slf4j.loggerfactory; import org.springframework.beans.factory.annotation.autowired; import org.springframework.scheduling.annotation.scheduled; import org.springframework.stereotype.component; @component public class mydaemonjob { private static final logger log = loggerfactory.getlogger(mydaemonjob.class); @postconstruct public void init() { log.info("mydaemonjob intialized " ); } @scheduled(fixeddelay = 1000) public void startdaemon() { try { log.info("mydaemonjob running ..."); } catch (exception e) { log.error("encountered error running scheduled job: " + e.getmessage()); } } }
it surely recognized spring bean , initialized, can see postconstruct
log. method @scheduled
annotation never runs although supposed run every 1 second.
here app context xml
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <context:component-scan base-package=" com.myproject.daemon.jobs, com.myproject.product" /> </beans>
thank quick help. helpful.
the code started working, once added config class annotations shown below --
package com.myproject; import org.springframework.context.annotation.configuration; import org.springframework.scheduling.annotation.enablescheduling; @configuration @enablescheduling public class appconfig { // various @bean definitions }
Comments
Post a Comment