forked from xuwujing/springBoot-study
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,188 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
springboot-summarizing/src/main/java/com/pancm/config/Swagger2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.pancm.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import springfox.documentation.builders.ApiInfoBuilder; | ||
import springfox.documentation.builders.PathSelectors; | ||
import springfox.documentation.builders.RequestHandlerSelectors; | ||
import springfox.documentation.service.ApiInfo; | ||
import springfox.documentation.spi.DocumentationType; | ||
import springfox.documentation.spring.web.plugins.Docket; | ||
import springfox.documentation.swagger2.annotations.EnableSwagger2; | ||
|
||
/** | ||
* | ||
* @Title: Swagger2 | ||
* @Description: | ||
* Swagger2配置 | ||
* @Version:1.0.0 | ||
* @author pancm | ||
* @date 2018年5月29日 | ||
*/ | ||
@Configuration | ||
@EnableSwagger2 | ||
public class Swagger2 { | ||
|
||
@Bean | ||
public Docket createRestApi() { | ||
return new Docket(DocumentationType.SWAGGER_2) | ||
.apiInfo(apiInfo()) | ||
.select() | ||
.apis(RequestHandlerSelectors.basePackage("com.pancm")) | ||
.paths(PathSelectors.any()) | ||
.build(); | ||
} | ||
|
||
private ApiInfo apiInfo() { | ||
return new ApiInfoBuilder() | ||
.title("Spring Boot中使用Swagger2构建RESTful APIs") | ||
.description("测试") | ||
.termsOfServiceUrl("http://www.panchengming.com/") | ||
.contact("xuwujing") | ||
.version("1.0") | ||
.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
springboot-summarizing/src/main/java/com/pancm/task/QuartzConfigration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.pancm.task; | ||
|
||
import org.quartz.Trigger; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.quartz.CronTriggerFactoryBean; | ||
import org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean; | ||
import org.springframework.scheduling.quartz.SchedulerFactoryBean; | ||
|
||
@Configuration | ||
public class QuartzConfigration { | ||
|
||
@Bean(name = "jobDetail") | ||
public MethodInvokingJobDetailFactoryBean detailFactoryBean(ScheduleTask task) { | ||
// ScheduleTask为需要执行的任务 | ||
MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean(); | ||
/* | ||
* 是否并发执行 | ||
* 例如每5s执行一次任务,但是当前任务还没有执行完,就已经过了5s了, | ||
* 如果此处为true,则下一个任务会bing执行,如果此处为false,则下一个任务会等待上一个任务执行完后,再开始执行 | ||
*/ | ||
jobDetail.setConcurrent(true); | ||
|
||
jobDetail.setName("scheduler");// 设置任务的名字 | ||
jobDetail.setGroup("scheduler_group");// 设置任务的分组,这些属性都可以存储在数据库中,在多任务的时候使用 | ||
|
||
/* | ||
* 这两行代码表示执行task对象中的scheduleTest方法。定时执行的逻辑都在scheduleTest。 | ||
*/ | ||
jobDetail.setTargetObject(task); | ||
|
||
jobDetail.setTargetMethod("scheduleTest"); | ||
return jobDetail; | ||
} | ||
|
||
@Bean(name = "jobTrigger") | ||
public CronTriggerFactoryBean cronJobTrigger(MethodInvokingJobDetailFactoryBean jobDetail) { | ||
CronTriggerFactoryBean tigger = new CronTriggerFactoryBean(); | ||
tigger.setJobDetail(jobDetail.getObject()); | ||
tigger.setCronExpression("0/30 * * * * ?");// 表示每隔30秒钟执行一次 | ||
//tigger.set | ||
tigger.setName("myTigger");// trigger的name | ||
return tigger; | ||
|
||
} | ||
|
||
@Bean(name = "scheduler") | ||
public SchedulerFactoryBean schedulerFactory(Trigger cronJobTrigger) { | ||
SchedulerFactoryBean bean = new SchedulerFactoryBean(); | ||
//设置是否任意一个已定义的Job会覆盖现在的Job。默认为false,即已定义的Job不会覆盖现有的Job。 | ||
bean.setOverwriteExistingJobs(true); | ||
// 延时启动,应用启动5秒后 ,定时器才开始启动 | ||
bean.setStartupDelay(5); | ||
// 注册定时触发器 | ||
bean.setTriggers(cronJobTrigger); | ||
return bean; | ||
} | ||
//多任务时的Scheduler,动态设置Trigger。一个SchedulerFactoryBean可能会有多个Trigger | ||
@Bean(name = "multitaskScheduler") | ||
public SchedulerFactoryBean schedulerFactoryBean(){ | ||
SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean(); | ||
return schedulerFactoryBean; | ||
} | ||
} |
Oops, something went wrong.