Reputation: 3
I want to run the following method every specific time in spring mvc project it works fine and print first output but it doesn't access the database so it doesn't display list
the method
public class ScheduleService {
@Autowired
private UserDetailService userDetailService;
public void performService() throws IOException {
System.out.println("first output");
List<UserDetail> list=userDetailService.getAll();
System.out.println(list);
}
config file
<!-- Spring's scheduling support -->
<task:scheduled-tasks scheduler="taskScheduler">
<task:scheduled ref="ScheduleService" method="performService" fixed-delay="2000"/>
</task:scheduled-tasks>
<!-- The bean that does the actual work -->
<bean id="ScheduleService" class="com.ctbllc.ctb.scheduling.ScheduleService" />
<!-- Defines a ThreadPoolTaskScheduler instance with configurable pool size. -->
<task:scheduler id="taskScheduler" pool-size="1"/>
Upvotes: 0
Views: 1999
Reputation: 3176
Write an integration test for that specific service and see if the service method calls returns anything at all. Manually testing always leads to such problems. Start with tests and debug if necessary.
Upvotes: 0
Reputation: 1565
try this (and remove bean definition from xml file):
@Component
public class ScheduleService {
@Autowired
private UserDetailService userDetailService;
@Scheduled(fixedDelay = 2000L) // in msec
public void performService() throws IOException {
System.out.println("first output");
List<UserDetail> list=userDetailService.getAll();
System.out.println(list);
}
}
Upvotes: 1