src/main/java/com/zy/system/entity/license/CustomKeyStoreParam.java
@@ -1,6 +1,7 @@ package com.zy.system.entity.license; import de.schlichtherle.license.AbstractKeyStoreParam; import org.apache.poi.util.IOUtils; import java.io.*; @@ -47,7 +48,8 @@ */ @Override public InputStream getStream() throws IOException { final InputStream in = new FileInputStream(new File(storePath)); final InputStream in = this.getClass().getClassLoader().getResourceAsStream(storePath); // final InputStream in = new FileInputStream(new File(storePath)); if (null == in) { throw new FileNotFoundException(storePath); } src/main/java/com/zy/system/entity/license/LicenseCheckListener.java
@@ -11,6 +11,7 @@ import org.springframework.stereotype.Component; import java.io.File; import java.io.InputStream; /** * 在项目启动时安装证书 @@ -64,18 +65,18 @@ logger.info("++++++++ 开始加载许可证 ++++++++"); try { String publicKeysStoreFileName = this.getClass().getClassLoader().getResource(publicKeysStorePath).getPath(); File publicKeysStoreFile = new File(publicKeysStoreFileName); String licensePathFileName = this.getClass().getClassLoader().getResource(licensePath).getPath(); File licensePathFile = new File(licensePathFileName); // String publicKeysStoreFileName = this.getClass().getClassLoader().getResource(publicKeysStorePath).getPath(); // File publicKeysStoreFile = new File(publicKeysStoreFileName); // // String licensePathFileName = this.getClass().getClassLoader().getResource(licensePath).getPath(); // File licensePathFile = new File(licensePathFileName); LicenseVerifyParam param = new LicenseVerifyParam(); param.setSubject(subject); param.setPublicAlias(publicAlias); param.setStorePass(storePass); param.setLicensePath(licensePathFile.getPath()); param.setPublicKeysStorePath(publicKeysStoreFile.getPath()); param.setLicensePath(licensePath); param.setPublicKeysStorePath(publicKeysStorePath); LicenseVerify licenseVerify = new LicenseVerify(); //安装证书 src/main/java/com/zy/system/entity/license/LicenseVerify.java
@@ -3,8 +3,11 @@ import de.schlichtherle.license.*; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.poi.util.IOUtils; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.text.DateFormat; import java.text.MessageFormat; import java.text.SimpleDateFormat; @@ -28,7 +31,12 @@ LicenseManager licenseManager = LicenseManagerHolder.getInstance(initLicenseParam(param)); licenseManager.uninstall(); result = licenseManager.install(new File(param.getLicensePath())); InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(param.getLicensePath()); File file = new File(param.getLicensePath()); try (FileOutputStream out = new FileOutputStream(file)) { IOUtils.copy(inputStream, out); } result = licenseManager.install(file); logger.info(MessageFormat.format("许可证加载成功,许可证有效期:{0} - {1}",format.format(result.getNotBefore()),format.format(result.getNotAfter()))); }catch (Exception e){ logger.error("许可证加载失败!",e);