- Following is code
- I am using spring.boot.version 1.4.1.RELEASE now
- Nothing is printed when I start the server
- I am using @Scheduled annotation to run a cron job but It never starts
- Same code works fine if I create new project and use following classes
Please suggest what can possibly go wrong ?
package com.equilar.bsp; import java.util.TimeZone; import javax.annotation.PreDestroy; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.web.SpringBootServletInitializer; import org.springframework.boot.orm.jpa.EntityScan; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.scheduling.annotation.EnableScheduling; import com.amazonaws.http.IdleConnectionReaper; import com.cloudinary.Cloudinary; import com.equilar.bsp.config.RedisConfig; import com.equilar.bsp.config.SecurityConfig; import com.equilar.bsp.mvc.MvcConfig; import com.equilar.bsp.util.JwtTokenGenerator; import com.equilar.bsp.util.Util; @SpringBootApplication @EnableScheduling @Configuration @EnableAutoConfiguration @EnableJpaAuditing //@ComponentScan(basePackages = "com.equilar" ,lazyInit = true) @EnableJpaRepositories("com.equilar") @EntityScan({"com.equilar.bsp.domain", "com.equilar.newcommon.folder.domain", "com.equilar.newcommon.pdf.domain"}) public class Application extends SpringBootServletInitializer { public static void main(String[] args) { // set default timezone first thing!! TimeZone.setDefault(TimeZone.getTimeZone("UTC")); SpringApplication.run(Application.class, args); JwtTokenGenerator.getStartTime(); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(applicationClass, SecurityConfig.class, MvcConfig.class, RedisConfig.class); } private static Class<Application> applicationClass = Application.class; @PreDestroy private void cleanUp() { /* try { // Shutting down AWS IdleConnectionReaper thread... IdleConnectionReaper.shutdown(); List<Thread> threadsList = getThreadByName("logback-loggly-appender"); if(!Util.isNullOrEmptyCollection(threadsList)){ for (Thread thread : threadsList) { thread.interrupt(); } } } catch (Throwable t) { // log error t.printStackTrace(); }*/ } /*public List<Thread> getThreadByName(String threadName) { List<Thread> threads = new ArrayList<Thread>(); for (Thread t : Thread.getAllStackTraces().keySet()) { if (t.getName().equals(threadName)){ threads.add(t); } } return threads; }*/ @Value("${CLOUDINARY_URL}") private String cloudinaryUrl; @Bean(name = "cloudinary") public Cloudinary Instance() { return new Cloudinary(cloudinaryUrl); } } package com.equilar.bsp.calc; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.scheduling.annotation.Scheduled; @org.springframework.stereotype.Component public class Component { private Logger logger = LoggerFactory.getLogger(this.getClass()); @Scheduled( cron = "0,30 * * * * *") public void cronJob() { logger.info("> cronJob"); logger.info("\n\n>>>>>>>>>>>>>>>>>>>>>>>>>> In Chron Job." ); logger.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>> "); } }
Asked
Active
Viewed 3,343 times
0

vk1
- 166
- 6
- 15
-
When you set a breakpoint in the `reportCurrentTime` method is that breakpoint reached when you start the application? – Josef Oct 24 '16 at 18:41
-
No, it never goes inside reportCurrentTime method – vk1 Oct 24 '16 at 20:22
-
how did you run the application? – kuhajeyan Oct 25 '16 at 05:36
-
I am running it as Spring Boot App and It's working now.I just restarted my STS.But same code doesn't work when I use it in my existing application. – vk1 Oct 25 '16 at 20:08
1 Answers
1
Your code sample looks totally fine for me. Moreover, I've created a project with sample code you've provided and it worked( with spring.boot.version 1.2.1.RELEASE ).
There is a similar project on github you may be interested in.

eparvan
- 1,639
- 1
- 15
- 26
-
I am running it as Spring Boot App and It's working now.I just restarted my STS.But same code doesn't work when I use it in my existing application.I updated my code. – vk1 Oct 25 '16 at 20:08