commit ff2ee61f40f41d2236a20839a496562f9fefe79a Author: MoonLoser <1938710636@qq.com> Date: Thu Jul 20 08:10:02 2023 +0800 初始化项目,编写简单逻辑 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..0baf95e --- /dev/null +++ b/pom.xml @@ -0,0 +1,78 @@ + + + 4.0.0 + com.julylies + webservicemonitor + 0.0.1-SNAPSHOT + webservicemonitor + webservicemonitor + + 1.8 + UTF-8 + UTF-8 + 2.3.12.RELEASE + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + UTF-8 + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + com.julylies.webservicemonitor.WebservicemonitorApplication + true + + + + repackage + + repackage + + + + + + + + diff --git a/src/main/java/com/julylies/webservicemonitor/WebservicemonitorApplication.java b/src/main/java/com/julylies/webservicemonitor/WebservicemonitorApplication.java new file mode 100644 index 0000000..ed88c3e --- /dev/null +++ b/src/main/java/com/julylies/webservicemonitor/WebservicemonitorApplication.java @@ -0,0 +1,20 @@ +package com.julylies.webservicemonitor; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableScheduling; + +/** + * @author JulyLies + * @version 1.0 + * @since 2023/7/20 07:33 + */ +@EnableScheduling +@SpringBootApplication +public class WebservicemonitorApplication { + + public static void main(String[] args) { + SpringApplication.run(WebservicemonitorApplication.class, args); + } + +} diff --git a/src/main/java/com/julylies/webservicemonitor/utils/CheckWebSerVice.java b/src/main/java/com/julylies/webservicemonitor/utils/CheckWebSerVice.java new file mode 100644 index 0000000..3831d1d --- /dev/null +++ b/src/main/java/com/julylies/webservicemonitor/utils/CheckWebSerVice.java @@ -0,0 +1,35 @@ +package com.julylies.webservicemonitor.utils; + +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +/** + * @author JulyLies + * @version 1.0 + * @since 2023/7/20 07:35 + */ +@Component +public class CheckWebSerVice { + private static final String TARGET_URL = "https://joplin.huangdf.xyz"; + + private final RestTemplate restTemplate; + + public CheckWebSerVice() { + this.restTemplate = new RestTemplate(); + } + + /** + * 每5分种执行一次检查 + */ + @Scheduled(fixedRate = 300000) + public void checkWebServiceStatus() { + try { + restTemplate.getForEntity(TARGET_URL, String.class); + System.out.println("Web服务正常运行中"); + } catch (Exception e) { + System.err.println("Web服务挂掉了!" + e.getMessage()); + // TODO: 发送通知短信 + } + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..e52b498 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,3 @@ +# 应用服务 WEB 访问端口 +server.port=8080 + diff --git a/src/test/java/com/julylies/webservicemonitor/WebservicemonitorApplicationTests.java b/src/test/java/com/julylies/webservicemonitor/WebservicemonitorApplicationTests.java new file mode 100644 index 0000000..bb764fb --- /dev/null +++ b/src/test/java/com/julylies/webservicemonitor/WebservicemonitorApplicationTests.java @@ -0,0 +1,13 @@ +package com.julylies.webservicemonitor; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class WebservicemonitorApplicationTests { + + @Test + void contextLoads() { + } + +}