فهرست منبع

Fix: profile and version info

wudi 4 سال پیش
والد
کامیت
6113fc7f8c

+ 32 - 2
pom.xml

@@ -10,7 +10,7 @@
 	</parent>
 	<groupId>com.mokasz</groupId>
 	<artifactId>image-pool</artifactId>
-	<version>1.0.0</version>
+	<version>2.0.0</version>
 	<name>image-pool</name>
 	<description>Image Pool Matching Service</description>
 	<properties>
@@ -61,7 +61,23 @@
 			<scope>test</scope>
 		</dependency>
 	</dependencies>
-
+	<profiles>
+		<profile>
+			<id>dev</id>
+			<activation>
+				<activeByDefault>true</activeByDefault>
+			</activation>
+			<properties>
+				<spring.profiles.active>dev</spring.profiles.active>
+			</properties>
+		</profile>
+		<profile>
+			<id>prod</id>
+			<properties>
+				<spring.profiles.active>prod</spring.profiles.active>
+			</properties>
+		</profile>
+	</profiles>
 	<build>
 		<plugins>
 			<plugin>
@@ -70,6 +86,14 @@
 				<configuration>
 					<fork>true</fork><!-- 热部署 -->
 				</configuration>
+				<executions>
+					<execution>
+						<id>build-info</id>
+						<goals>
+							<goal>build-info</goal>
+						</goals>
+					</execution>
+				</executions>
 			</plugin>
 			<plugin>
 				<groupId>org.apache.maven.plugins</groupId>
@@ -80,6 +104,12 @@
 				</configuration>
 			</plugin>
 		</plugins>
+		<resources>
+			<resource>
+				<directory>src/main/resources</directory>
+				<filtering>true</filtering>
+			</resource>
+		</resources>
 	</build>
 
 </project>

+ 9 - 4
src/main/java/com/mokasz/pool/image/restful/controller/IndexController.java

@@ -2,7 +2,8 @@ package com.mokasz.pool.image.restful.controller;
 
 import com.mokasz.pool.image.restful.entity.IndexResponse;
 import lombok.RequiredArgsConstructor;
-import org.springframework.beans.factory.annotation.Value;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.info.BuildProperties;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -12,8 +13,12 @@ import java.net.UnknownHostException;
 @RestController
 @RequiredArgsConstructor
 public class IndexController {
-    @Value("${pom.version}")
-    private String version;
+    BuildProperties buildProperties;
+
+    @Autowired
+    public IndexController(BuildProperties buildProperties) {
+        this.buildProperties = buildProperties;
+    }
 
     private String getHostname() {
         try {
@@ -25,6 +30,6 @@ public class IndexController {
 
     @GetMapping("/")
     public IndexResponse index() {
-        return new IndexResponse(version, getHostname());
+        return new IndexResponse(buildProperties.getVersion(), getHostname());
     }
 }

+ 7 - 0
src/main/resources/application-dev.properties

@@ -0,0 +1,7 @@
+# app
+debug=false
+# db
+spring.datasource.driverClassName = org.postgresql.Driver
+spring.datasource.url = jdbc:postgresql://hgprecn-cn-2r428a8it006-cn-shanghai.hologres.aliyuncs.com:80/galaxy_new?useUnicode=true&useSSL=false
+spring.datasource.username = LTAI5t8TZysKUFex7CVamCDj
+spring.datasource.password = ibLOdbZUPm0tpIDfnZ7spOuRY4k09o

+ 7 - 0
src/main/resources/application-prod.properties

@@ -0,0 +1,7 @@
+# app
+debug=false
+# db
+spring.datasource.driverClassName = org.postgresql.Driver
+spring.datasource.url = jdbc:postgresql://hgprecn-cn-2r428a8it006-cn-shanghai-vpc.hologres.aliyuncs.com:80/galaxy_new?useUnicode=true&useSSL=false
+spring.datasource.username = LTAI5t8TZysKUFex7CVamCDj
+spring.datasource.password = ibLOdbZUPm0tpIDfnZ7spOuRY4k09o

+ 0 - 7
src/main/resources/application.dev.properties

@@ -1,7 +0,0 @@
-# app
-debug=false
-# db
-spring.datasource.driverClassName = org.postgresql.Driver
-spring.datasource.url = jdbc:postgresql://gp-uf61gv6sn7u6ij7kbo-master.gpdbmaster.rds.aliyuncs.com:5432/wudi_test?useUnicode=true&useSSL=false
-spring.datasource.username = wudi
-spring.datasource.password = 135790

+ 2 - 6
src/main/resources/application.properties

@@ -1,8 +1,4 @@
 # app
 debug=false
-pom.version=@project.version@
-# db
-spring.datasource.driverClassName = org.postgresql.Driver
-spring.datasource.url = jdbc:postgresql://gp-uf61gv6sn7u6ij7kb-master.gpdbmaster.rds.aliyuncs.com:5432/wudi_test?useUnicode=true&useSSL=false
-spring.datasource.username = wudi
-spring.datasource.password = 135790
+# profile
+spring.profiles.active=@spring.profiles.active@