AE86 3 gadi atpakaļ
vecāks
revīzija
8233d85ce4

+ 44 - 0
dbsyncer-common/src/main/java/org/dbsyncer/common/config/AppConfig.java

@@ -0,0 +1,44 @@
+package org.dbsyncer.common.config;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @author AE86
+ * @version 1.0.0
+ * @date 2022/5/18 0:04
+ */
+@Configuration
+@ConfigurationProperties(prefix = "info.app")
+public class AppConfig {
+
+    private String name;
+
+    private String version;
+
+    private String copyright;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getVersion() {
+        return version;
+    }
+
+    public void setVersion(String version) {
+        this.version = version;
+    }
+
+    public String getCopyright() {
+        return copyright;
+    }
+
+    public void setCopyright(String copyright) {
+        this.copyright = copyright;
+    }
+}

+ 5 - 7
dbsyncer-plugin/src/main/java/org/dbsyncer/plugin/service/DemoConvertServiceImpl.java

@@ -1,9 +1,10 @@
 package org.dbsyncer.plugin.service;
 
+import org.dbsyncer.common.config.AppConfig;
 import org.dbsyncer.common.spi.ConvertService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.util.List;
@@ -14,11 +15,8 @@ public class DemoConvertServiceImpl implements ConvertService {
 
     private final Logger logger = LoggerFactory.getLogger(getClass());
 
-    /**
-     * 版本号
-     */
-    @Value(value = "${info.app.version}")
-    private String version;
+    @Autowired
+    private AppConfig appConfig;
 
     @Override
     public void convert(List<Map> source, List<Map> target) {
@@ -31,7 +29,7 @@ public class DemoConvertServiceImpl implements ConvertService {
 
     @Override
     public String getVersion() {
-        return version;
+        return appConfig.getVersion();
     }
 
     public String getName() {

+ 4 - 22
dbsyncer-web/src/main/java/org/dbsyncer/web/controller/index/IndexController.java

@@ -4,9 +4,8 @@ import org.dbsyncer.biz.ConnectorService;
 import org.dbsyncer.biz.MappingService;
 import org.dbsyncer.biz.vo.RestResult;
 import org.dbsyncer.biz.vo.VersionVo;
+import org.dbsyncer.common.config.AppConfig;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.context.annotation.PropertySource;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.ModelMap;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -18,7 +17,6 @@ import java.io.UnsupportedEncodingException;
 
 @Controller
 @RequestMapping("/index")
-@ConfigurationProperties(prefix = "info.app")
 public class IndexController {
 
     @Autowired
@@ -27,9 +25,8 @@ public class IndexController {
     @Autowired
     private MappingService mappingService;
 
-    private String name;
-
-    private String copyright;
+    @Autowired
+    private AppConfig appConfig;
 
     @GetMapping("")
     public String index(HttpServletRequest request, ModelMap model) {
@@ -41,22 +38,7 @@ public class IndexController {
     @GetMapping("/version.json")
     @ResponseBody
     public RestResult version() throws UnsupportedEncodingException {
-        return RestResult.restSuccess(new VersionVo(name, copyright));
+        return RestResult.restSuccess(new VersionVo(appConfig.getName(), appConfig.getCopyright()));
     }
 
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public String getCopyright() {
-        return copyright;
-    }
-
-    public void setCopyright(String copyright) {
-        this.copyright = copyright;
-    }
 }

+ 6 - 9
dbsyncer-web/src/main/java/org/dbsyncer/web/controller/plugin/PluginController.java

@@ -4,11 +4,11 @@ import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.dbsyncer.biz.PluginService;
 import org.dbsyncer.biz.vo.RestResult;
+import org.dbsyncer.common.config.AppConfig;
 import org.dbsyncer.common.util.JsonUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.ModelMap;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -29,16 +29,13 @@ public class PluginController {
     @Autowired
     private PluginService pluginService;
 
-    /**
-     * 版本号
-     */
-    @Value(value = "${info.app.version}")
-    private String version;
+    @Autowired
+    private AppConfig appConfig;
 
     @RequestMapping("")
     public String index(ModelMap model) {
         model.put("plugins", pluginService.getPluginAll());
-        model.put("version", version);
+        model.put("version", appConfig.getVersion());
         return "plugin/plugin";
     }
 
@@ -71,9 +68,9 @@ public class PluginController {
 
     @GetMapping("/download")
     public void download(HttpServletResponse response) {
-        String fileName = String.format("dbsyncer-common-%s.jar", version);
+        String fileName = String.format("dbsyncer-common-%s.jar", appConfig.getVersion());
         File file = new File(pluginService.getLibraryPath() + fileName);
-        if(!file.exists()){
+        if (!file.exists()) {
             write(response, RestResult.restFail("Could not find file", 404));
             return;
         }