Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 用springmvc调度任务_Java_Spring_Spring Mvc_Scheduled Tasks_Quartz Scheduler - Fatal编程技术网

Java 用springmvc调度任务

Java 用springmvc调度任务,java,spring,spring-mvc,scheduled-tasks,quartz-scheduler,Java,Spring,Spring Mvc,Scheduled Tasks,Quartz Scheduler,我想在SpringMVC项目中的每个特定时间运行以下方法,它工作良好并打印第一个输出 但它不访问数据库,因此不显示列表 方法 public class ScheduleService { @Autowired private UserDetailService userDetailService; public void performService() throws IOException { System.out.println("first output"); Lis

我想在SpringMVC项目中的每个特定时间运行以下方法,它工作良好并打印第一个输出 但它不访问数据库,因此不显示列表

方法

 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);

}
公共类调度服务{
@自动连线
私有UserDetailService UserDetailService;
public void performService()引发IOException{
System.out.println(“第一次输出”);
List List=userDetailService.getAll();
系统输出打印项次(列表);
}
配置文件

 <!-- 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"/>      

试试这个(并从xml文件中删除bean定义):

@组件
公共类调度服务{
@自动连线
私有UserDetailService UserDetailService;
@计划(固定延迟=2000L)//以毫秒为单位
public void performService()引发IOException{
System.out.println(“第一次输出”);
List List=userDetailService.getAll();
系统输出打印项次(列表);
}
}

为该特定服务编写一个集成测试,看看服务方法调用是否返回任何结果。手动测试总是会导致此类问题。从测试开始,必要时进行调试。

因此,这不是关于计划任务的问题,日志怎么说。用户服务访问dbI如何尝试在con中运行它troller并正常工作,但当将其放入带有@service annotation的ScheduleService类中时,它不工作,该方法只打印(第一次输出),然后您的
getAll()
方法不知何故被阻塞。注释掉该行并尝试运行。在本例中,进一步调试您的服务方法,它的
getAll()
.getAll方法在控制器中使用时运行良好,但此处不起作用
@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);

    }

}