Skip to content

Commit e33c935

Browse files
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # README.md
2 parents a398565 + 951300f commit e33c935

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
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
#### 构建
4849
1. 先通过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

docker-compose.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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"

src/main/java/cn/netbuffer/springboot/demo/SpringBootDemoApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
import org.springframework.boot.autoconfigure.SpringBootApplication;
77
import org.springframework.retry.annotation.EnableRetry;
88
import org.springframework.scheduling.annotation.EnableAsync;
9+
import org.springframework.scheduling.annotation.EnableScheduling;
910

1011
@Slf4j
1112
@EnableRetry
1213
@EnableAsync
14+
@EnableScheduling
1315
@SpringBootApplication
1416
public class SpringBootDemoApplication implements CommandLineRunner {
1517

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
}

0 commit comments

Comments
 (0)