Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
My scheduled task is as follows
But the application does not respond when i use
@Scheduled(cron="0 46 17 * * *")
And when I use
@Scheduled(fixedRate = 50000)
, When saving information on mongoDB The program gives an error
[ scheduling-1] o.s.s.s.TaskUtils$LoggingErrorHandler : Unexpected error occurred in scheduled task.
: An unexpected error occurred during scheduled work.
java.lang.NullPointerException
please help me for fix my cod .
@Scheduled(cron="0 46 17 * * *")
// @Scheduled(fixedRate = 5000)
@RequestMapping("/closeAttendance}")
public void cloceAttendance() {
System.out.println("-1");
AttendanceService attendanceService=new AttendanceService();
Date date=attendanceService.getCurrentDate();
System.out.println("1");
List<Attendance> attendances=arepo.findByDate(date);
if(attendances!=null) {
System.out.println("attendances"+attendances.size());
System.out.println("2");
for(Attendance attendance:attendances) {
System.out.println("3");
attendance=attendanceService.closeAttendance(attendance);
System.out.println("4");
System.out.println("attendance"+attendance.getDate()+" "+ attendance.getPerson());
// arepo.save(attendance);
–
There is nothing wrong with your code. The only thing that is missing is the
annotation
@EnableScheduling
.
Use this
annotation
at
class level
and your code will work fine.
Please don't forgot to
up-vote
if this solution works for you.
–
–
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling ;
import org.springframework.scheduling.annotation.Scheduled;
com.winner.etyping.domain.RegParentDomain;
import com.winner.etyping.domain.SchoolRegistrationDomain;
import com.winner.etyping.domain.StudentDomain;
@EnableScheduling
@Servic
public class StudentServiceImpl implements StudentService{
@Autowired
private ClassService classserice;
@Autowired
private DivisionService div;
@Autowired
private RegParentService parent;
@Autowired
private SchoolregistrationService school;
@Autowired
private StudentDao studendao;
@Transactional
public List<StudentDomain> getByClassAndDivId(Integer classid, Integer div,Integer school) {
return studendao.getByClassAndDivId(classid,div,school);
**@Scheduled(cron="0 0 10 * * ?")**
@Transactional
public void sendBirthdayWish() throws Exception {
studendao.sendBirthdayWish();
@Transactional
public void sendNotificationToClassStudent(ClassDomain classid, SchoolRegistrationDomain schoolid , String Notification) throws Exception {
studendao.sendNotificationToClassStudent(classid,schoolid,Notification);
Thanks for contributing an answer to Stack Overflow!
-
Please be sure to
answer the question
. Provide details and share your research!
But
avoid
…
-
Asking for help, clarification, or responding to other answers.
-
Making statements based on opinion; back them up with references or personal experience.
To learn more, see our
tips on writing great answers
.