springboot用法和与各种框架、组件等结合使用,包括springboot的注解分析、路径分析、取得内置对象、项目打包、配置环境属性、读取资源文件、Bean配置、模板渲染、基于yml的多profile配置、基于properties的多profile、添加数据验证、配置错误页、全局异常处理、配置Tomcat运行、配置https访问路径、信息显示、内置对象、显示对象信息、文件上传、使用文件服务器、拦截器、配置druid数据库连接池、整合MyBatis框架、事务控制、Druid监控、整合ActiveMQ、整合RabbitMQ、整合kafka、邮件发送、定时调度、Actuator监控、整合Redis数据库、整合Restfui框架、整合Shiro
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package cn.mldn.microboot;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@SpringBootApplication // 启动SpringBoot程序,而后自带子包扫描
|
||||
@EnableScheduling // 启用间隔调度
|
||||
public class StartSpringBootMain {
|
||||
public static void main(String[] args) throws Exception {
|
||||
SpringApplication.run(StartSpringBootMain.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.mldn.microboot.config;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
|
||||
@Configuration // 定时调度的配置类一定要实现指定的父接口
|
||||
public class SchedulerConfig implements SchedulingConfigurer {
|
||||
@Override
|
||||
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { // 开启一个线程调度池
|
||||
taskRegistrar.setScheduler(Executors.newScheduledThreadPool(100));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package cn.mldn.microboot.task;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MyScheduler {
|
||||
@Scheduled(fixedRate = 2000) // 采用间隔调度,每2秒执行一次
|
||||
public void runJobA() { // 定义一个要执行的任务
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("【*** MyTaskA - 间隔调度 ***】"
|
||||
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
|
||||
.format(new Date()));
|
||||
}
|
||||
@Scheduled(cron = "* * * * * ?") // 每秒调用一次
|
||||
public void runJobB() {
|
||||
System.err.println("【*** MyTaskB - 间隔调度 ***】"
|
||||
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
|
||||
.format(new Date()));
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package cn.mldn.microboot.util.controller;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.context.MessageSource;
|
||||
|
||||
public abstract class AbstractBaseController {
|
||||
@Resource
|
||||
private MessageSource messageSource; // 自动注入此资源对象
|
||||
public String getMessage(String key, String... args) {
|
||||
return this.messageSource.getMessage(key, args, Locale.getDefault());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.mldn.microboot.vo;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class Dept implements Serializable {
|
||||
private Long deptno ;
|
||||
private String dname ;
|
||||
public Long getDeptno() {
|
||||
return deptno;
|
||||
}
|
||||
public void setDeptno(Long deptno) {
|
||||
this.deptno = deptno;
|
||||
}
|
||||
public String getDname() {
|
||||
return dname;
|
||||
}
|
||||
public void setDname(String dname) {
|
||||
this.dname = dname;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Dept [deptno=" + deptno + ", dname=" + dname + "]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package cn.mldn.microboot.vo;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class Member implements Serializable {
|
||||
private Long mid ;
|
||||
private String name ;
|
||||
private Integer age ;
|
||||
private Date birthday ;
|
||||
private Double salary ;
|
||||
public Long getMid() {
|
||||
return mid;
|
||||
}
|
||||
public void setMid(Long mid) {
|
||||
this.mid = mid;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public Integer getAge() {
|
||||
return age;
|
||||
}
|
||||
public void setAge(Integer age) {
|
||||
this.age = age;
|
||||
}
|
||||
public Date getBirthday() {
|
||||
return birthday;
|
||||
}
|
||||
public void setBirthday(Date birthday) {
|
||||
this.birthday = birthday;
|
||||
}
|
||||
public Double getSalary() {
|
||||
return salary;
|
||||
}
|
||||
public void setSalary(Double salary) {
|
||||
this.salary = salary;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user