无法在SpringMVC Java中运行固定速率调度程序

时间:2017-08-14 00:23:00

标签: java spring-mvc scheduled-tasks

我正在尝试运行任务调度程序,但我得到以下错误:

"C:\Program Files\Java\jdk1.8.0_121\bin\java"  com.mthree.util.App
Error: Could not find or load main class com.mthree.util.App

Process finished with exit code 1

FixedRateScheduler代码

import org.springframework.scheduling.annotation.Scheduled;
import java.util.Date;

public class FixedRateScheduler {

@Scheduled(fixedRate = 1000)
public void run() throws InterruptedException{
    System.out.println("livePrice: "+ new Date());
    Thread.sleep(3000);
   }
}

LivePrice-servlet.xml中

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:task="http://www.springframework.org/schema/cache"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
   http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">

<task:annotation-driven />
<mvc:annotation-driven />
<context:annotation-config />

<bean id="fixedRateScheduler" class="com.mthree.util.FixedRateScheduler" ></bean>

<context:component-scan base-package="com.mthree.*" />

主类 - App.java

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {
    public static void main(String [] args){
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("LivePrice-servlet.xml");
    }
}

目录结构

enter image description here

0 个答案:

没有答案