Skip to content

Commit 53867be

Browse files
wildeslamyushuwang
andauthored
Feat/pom version (#114)
* feat: get pom version at vi/health interface * feat: get pom version at vi/health interface * feat: get pom version at vi/health interface --------- Co-authored-by: yushuwang <[email protected]>
1 parent e77c73b commit 53867be

File tree

4 files changed

+12
-25
lines changed

4 files changed

+12
-25
lines changed

arex-storage-web-api/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,6 @@
112112
<artifactId>log4j-mongodb4</artifactId>
113113
<groupId>org.apache.logging.log4j</groupId>
114114
</dependency>
115-
<dependency>
116-
<groupId>org.apache.maven</groupId>
117-
<artifactId>maven-model</artifactId>
118-
<version>3.6.3</version>
119-
</dependency>
120115

121116
</dependencies>
122117
<modelVersion>4.0.0</modelVersion>

arex-storage-web-api/src/main/java/com/arextest/storage/web/controller/CheckHealthController.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
import com.arextest.common.model.response.Response;
44
import com.arextest.common.utils.ResponseUtils;
5-
import java.io.FileReader;
65
import lombok.extern.slf4j.Slf4j;
7-
import org.apache.maven.model.Model;
8-
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
6+
import org.springframework.beans.factory.annotation.Value;
97
import org.springframework.stereotype.Controller;
108
import org.springframework.web.bind.annotation.CrossOrigin;
119
import org.springframework.web.bind.annotation.GetMapping;
@@ -17,27 +15,13 @@
1715
@RequestMapping("/vi/")
1816
@CrossOrigin(origins = "*", maxAge = 3600)
1917
public class CheckHealthController {
20-
private static Model POM_MODEL;
21-
22-
static {
23-
try {
24-
POM_MODEL = new MavenXpp3Reader().read(new FileReader("pom.xml"));
25-
} catch (Exception e) {
26-
LOGGER.error("Read pom failed!", e);
27-
}
28-
}
18+
@Value("${pom.version}")
19+
private String VERSION;
2920

3021
@GetMapping(value = "/health", produces = "application/json")
3122
@ResponseBody
3223
public Response checkHealth() {
33-
return ResponseUtils.successResponse(getVersion());
24+
return ResponseUtils.successResponse(VERSION);
3425
}
3526

36-
private static String getVersion() {
37-
if (POM_MODEL != null) {
38-
return POM_MODEL.getVersion();
39-
} else {
40-
return "error";
41-
}
42-
}
4327
}

arex-storage-web-api/src/main/resources/application.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@ arex:
4040
similarity:
4141
strategy:
4242
appIds:
43+
pom:
44+
version: ${project.version}

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@
209209
</activation>
210210
<build>
211211
<finalName>arex-storage-web-api</finalName>
212+
<resources>
213+
<resource>
214+
<directory>src/main/resources</directory>
215+
<filtering>true</filtering>
216+
</resource>
217+
</resources>
212218
<plugins>
213219
<plugin>
214220
<artifactId>maven-compiler-plugin</artifactId>

0 commit comments

Comments
 (0)