Skip to content

Commit 8f942ff

Browse files
committed
echo application info
1 parent 21286e6 commit 8f942ff

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

help/http-requests.http

+3
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ GET http://localhost:9100/param/getRemotePort
5858

5959
### /param/getLocalPort
6060
GET http://localhost:9100/param/getLocalPort
61+
62+
### /application/info
63+
GET http://localhost:9100/application/info
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package cn.netbuffer.springboot.demo.controller;
2+
3+
import io.micrometer.core.instrument.util.IOUtils;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.springframework.context.ApplicationContext;
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RestController;
9+
import javax.annotation.Resource;
10+
import java.io.IOException;
11+
12+
@Slf4j
13+
@RestController
14+
@RequestMapping("/application/info")
15+
public class ApplicationInfoController {
16+
17+
@Resource
18+
private ApplicationContext applicationContext;
19+
private String gitProperties = "git.properties";
20+
21+
@GetMapping
22+
public String info() {
23+
org.springframework.core.io.Resource resource = applicationContext.getResource("classpath:"+gitProperties);
24+
log.debug("check {} isExist={}", gitProperties, resource.exists());
25+
String info = "nothing";
26+
if (resource.exists()) {
27+
try {
28+
info = IOUtils.toString(resource.getInputStream());
29+
} catch (IOException e) {
30+
info = "error info";
31+
log.error("read {} error", gitProperties, e);
32+
}
33+
}
34+
return info;
35+
}
36+
37+
}

0 commit comments

Comments
 (0)