scheadule task example
This commit is contained in:
1 parent
24c7a287c6
commit
99c1aef51c
2 files changed
+31
-2
No files matched your search
@@ -1,11 +1,15 @@
|
||||
package application;
|
||||
|
||||
import application.repositories.RoleRepository;
|
||||
import application.utils.TokensGenerator;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
import application.repositories.RoleRepository;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
/**
|
||||
* Created by lukasgol on 01.04.14.
|
||||
@@ -14,13 +18,20 @@ import application.repositories.RoleRepository;
|
||||
@ComponentScan
|
||||
@EnableAutoConfiguration
|
||||
@ImportResource("Spring-Module.xml")
|
||||
@EnableScheduling
|
||||
public class Config {
|
||||
|
||||
@Scheduled(fixedRate = 500)
|
||||
public void generatePassword() {
|
||||
TokensGenerator.generatePassword();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
ConfigurableApplicationContext context = SpringApplication.run(Config.class, args);
|
||||
|
||||
RoleRepository rr = context.getBean(RoleRepository.class);
|
||||
System.out.print(rr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package application.utils;
|
||||
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Created by lukasgol on 21.04.14.
|
||||
*/
|
||||
public class TokensGenerator {
|
||||
|
||||
@Scheduled(fixedRate = 500)
|
||||
public static void generatePassword() {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
|
||||
System.out.println("The time is new password "+Math.random() +" [" +dateFormat.format(new Date())+"]");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user