File tree Expand file tree Collapse file tree 4 files changed +37
-1
lines changed
src/main/java/cn/netbuffer/springboot/demo Expand file tree Collapse file tree 4 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 1414* [ ResponseEntityExceptionHandler] ( https://docs.spring.io/spring-framework/docs/5.3.6/javadoc-api/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.html )
1515* [ requestmapping] ( https://docs.spring.io/spring-framework/docs/5.3.6/reference/html/web.html#mvc-ann-requestmapping-registration )
1616* [ hibernate_validator_reference] ( https://docs.jboss.org/hibernate/validator/6.2/reference/en-US/pdf/hibernate_validator_reference.pdf#validator-gettingstarted )
17+ * https://docs.docker.com/compose/compose-file/compose-file-v3/#build
1718* https://hub.docker.com/_/openjdk
1819
1920### server.servlet.session.timeout
@@ -46,10 +47,11 @@ d for days
4647
4748#### 构建
48491 . 先通过maven打包到target目录下
49- 2 . 执行构建指令:docker build -t netbuffer/spring-boot-demo:1.0 .
50+ 2 . 执行构建指令:` cd target; docker build -f ../Dockerfile - t netbuffer/spring-boot-demo:1.0 ../ ` ( ` docker build -t netbuffer/spring-boot-demo:1.0 . ` )
5051
5152#### 运行
5253* docker run --rm -it -p 9100:9100 netbuffer/spring-boot-demo:1.0
54+ * docker-compose up (使用docker-compose启动服务)
5355
5456#### 发布到DockerHub
5557> 需要注册DockerHub身份,再docker login登录对应的Registry
Original file line number Diff line number Diff line change 1+ version : " 3.9"
2+ # 定义服务
3+ services :
4+ spring-boot-demo :
5+ build :
6+ context : .
7+ dockerfile : Dockerfile
8+ labels :
9+ cn.netbuffer.springboot.demo.description : " spring-boot-demo webapp"
10+ cn.netbuffer.springboot.demo.author : " netbuffer"
11+ cn.netbuffer.springboot.demo.label-with-empty-value : " "
12+ image : netbuffer/spring-boot-demo:1.0
13+ ports :
14+ - " 9100:9100"
15+ container_name : spring-boot-demo-container
16+ restart : " no"
Original file line number Diff line number Diff line change 66import org .springframework .boot .autoconfigure .SpringBootApplication ;
77import org .springframework .retry .annotation .EnableRetry ;
88import org .springframework .scheduling .annotation .EnableAsync ;
9+ import org .springframework .scheduling .annotation .EnableScheduling ;
910
1011@ Slf4j
1112@ EnableRetry
1213@ EnableAsync
14+ @ EnableScheduling
1315@ SpringBootApplication
1416public class SpringBootDemoApplication implements CommandLineRunner {
1517
Original file line number Diff line number Diff line change 1+ package cn .netbuffer .springboot .demo .config ;
2+
3+ import lombok .extern .slf4j .Slf4j ;
4+ import org .springframework .context .annotation .Configuration ;
5+ import org .springframework .scheduling .annotation .Scheduled ;
6+
7+ @ Slf4j
8+ @ Configuration
9+ public class ScheduleTask {
10+
11+ @ Scheduled (cron = "0 0 */1 * * ?" )
12+ public void print (){
13+ log .info ("print task exec" );
14+ }
15+
16+ }
You can’t perform that action at this time.
0 commit comments