Spring MVC定時服務

2022-04-17 13:41:00 字數 3164 閱讀 2255

spring-mvc-config.xml

<

context:component-scan

base-package

="com.bf"

>

context:component-scan

>

<

task:annotation-driven

/>

<

mvc:annotation-driven

/>

spring-core-config.xml

<

context:component-scan

base-package

="com.bf"

>

<

context:exclude-filter

expression

="org.springframework.stereotype.controller"

type

="annotation"

/>

context:component-scan

>

web.xml

<

servlet

>

<

servlet-name

>spring-dispatcher

servlet-name

>

<

servlet-class

>org.springframework.web.servlet.dispatcherservlet

servlet-class

>

<

init-param

>

<

param-name

>contextconfiglocation

param-name

>

<

param-value

>/web-inf/spring-mvc-config.xml

param-value

>

init-param

>

<

load-on-startup

>1

load-on-startup

>

servlet

>

<

>

<

servlet-name

>spring-dispatcher

servlet-name

>

<

url-pattern

>/

url-pattern

>

>

<

listener

>

<

listener-class

>org.springframework.web.context.contextloaderlistener

listener-class

>

listener

>

<

listener

>

<

listener-class

>org.springframework.web.context.request.requestcontextlistener

listener-class

>

listener

>

<

context-param

>

<

param-name

>contextconfiglocation

param-name

>

<

param-value

>/web-inf/spring-core-config.xml

param-value

>

context-param

>

@component

public

class

autoservice {

private

static logger logger = logger.getlogger(autoservice.class

);

@autowired

private

memberwechatservice memberwechatservice;

/*cron表示式:

*(秒0-59)

*(分鐘0-59)

*(小時0-23)

*(日期1-31)

*(月份1-12或是jan-dec)

*(星期1-7或是sun-sat)

*/@scheduled(cron = "0 32 * * * *") //

每週日下午6:00

public

void notifytutor() {

server.xml

<

host

autodeploy

="true"

name

="localhost"

unpackwars

="true"

>

這種配置可以定義執行。

但是以下配置方式,對事務是有效的,感覺事務與定時服務有衝突,沒找到解決辦法

spring-mvc-config.xml

<

context:component-scan

base-package

="com.bf"

use-default-filters

="false"

>

<

context:include-filter

type

="annotation"

expression

="org.springframework.stereotype.controller"

/>

context:component-scan

>

Spring MVC 定時任務

1.在springmvc配置檔案中新增 xmlns task xsi schemalocation後追加 spring task 3.2.xsd 如圖所示 2.編寫測試類 package com.vrveis.roundtrip.task import org.springframework.sch...

SpringMVC定時任務

在springmvc.xml新增如下內容 在xmlns中新增 xmlns task 在xsi中新增 spring task 3.2.xsd在中間新增 新建timertask類 該類需要放在springmvc註解的框架下。如下 import org.springframework.scheduling...

springmvc配置quartz定時任務

springmvc配置quartz定時任務 job1 class com.rionsoft.web.quartz.szzzptquartztask queryworkercheckondetail class org.springframework.scheduling.quartz.methodi...