Przeglądaj źródła

修改验证,打成jar包之后无法获取jar包内的文件

wukai 1 rok temu
rodzic
commit
c73854438a

+ 1 - 0
doc-admin/src/main/resources/application-test.yml

@@ -19,6 +19,7 @@ ruoyi:
 license:
   subject: doc_test
   licensePath: D:\SYSTEM\Desktop\temp\license.lic
+  keyStore: D:\SYSTEM\Desktop\temp\license\publicKeys.keystore
 
 # 开发环境配置
 server:

+ 3 - 1
doc-admin/src/main/resources/application.yml

@@ -15,7 +15,9 @@ ruoyi:
 #证书相关配置
 license:
   subject: doc_test
-  licensePath: D:\SYSTEM\Desktop\temp\license\license.lic
+  licensePath: D:\code\2023\doc\license.lic
+  keyStore: D:\code\2023\doc\doc-admin\src\main\resources\license\publicKeys.keystore
+
 # 服务配置
 server:
   servlet:

+ 10 - 9
doc-common/src/main/java/com/doc/common/data/DataListener.java

@@ -7,6 +7,7 @@ import com.doc.common.utils.encrypt.Sm2Util;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.system.ApplicationHome;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationListener;
 import org.springframework.context.ConfigurableApplicationContext;
@@ -21,7 +22,6 @@ import org.springframework.stereotype.Component;
 import javax.annotation.Resource;
 import java.io.File;
 import java.io.FileWriter;
-import java.util.Objects;
 
 /**
  * 授权许可验证监听器
@@ -46,6 +46,11 @@ public class DataListener implements ApplicationListener<ContextRefreshedEvent>
      */
     @Value("${license.licensePath}")
     private String licensePath;
+    /**
+     * 公钥存放路径
+     */
+    @Value("${license.keyStore}")
+    private String keyStore;
 
     public DataListener() {
     }
@@ -58,16 +63,12 @@ public class DataListener implements ApplicationListener<ContextRefreshedEvent>
                 try {
                     logger.info("++++++++ 开始安装证书 ++++++++");
 
-                    //公钥存放位置
-                    File file = new File(Objects.requireNonNull(this.getClass().getResource("/")).getPath());
-                    String publicKeysStorePath = file.getAbsolutePath() + File.separator + "license/publicKeys.keystore";
-
                     DataPara param = new DataPara();
                     param.setSubject(subject);
                     param.setLicensePath(licensePath);
                     param.setPublicAlias("publicKey");
                     param.setStorePass("jjt@2023");
-                    param.setPublicKeysStorePath(publicKeysStorePath);
+                    param.setPublicKeysStorePath(keyStore);
 
                     DataVerify dataVerify = new DataVerify();
                     //安装证书
@@ -107,9 +108,9 @@ public class DataListener implements ApplicationListener<ContextRefreshedEvent>
             } else {//其他服务器类型
                 infos = new LinuxInfos();
             }
-            File file = new File(Objects.requireNonNull(this.getClass().getResource("/")).getPath());
-            String path = file.getParentFile().getParentFile().getParentFile().getAbsolutePath();
-            path = path + File.separator + "register_code.txt";
+
+            ApplicationHome home = new ApplicationHome(getClass());
+            String path = home.getSource().getParent() + File.separator + "register_code.txt";
             File codeFile = new File(path);
             try (FileWriter fw = new FileWriter(codeFile)) {
                 //json对象转字符串