Commit 60560651 by hy

添加LicenseProperties

parent b3a26a6f
...@@ -3,6 +3,7 @@ package com.tbyf.license; ...@@ -3,6 +3,7 @@ package com.tbyf.license;
import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration; import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -10,6 +11,7 @@ import org.springframework.core.Ordered; ...@@ -10,6 +11,7 @@ import org.springframework.core.Ordered;
import javax.servlet.MultipartConfigElement; import javax.servlet.MultipartConfigElement;
@EnableConfigurationProperties(LicenseProperties.class)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@AutoConfiguration(after = {DispatcherServletAutoConfiguration.class}) @AutoConfiguration(after = {DispatcherServletAutoConfiguration.class})
public class LicenseAutoConfiguration { public class LicenseAutoConfiguration {
...@@ -30,9 +32,10 @@ public class LicenseAutoConfiguration { ...@@ -30,9 +32,10 @@ public class LicenseAutoConfiguration {
} }
@Bean @Bean
public ServletRegistrationBean<LicenseInstallationServlet> licenseServlet() { public ServletRegistrationBean<LicenseInstallationServlet> licenseServlet(LicenseProperties licenseProperties) {
LicenseInstallationServlet servlet = new LicenseInstallationServlet(); LicenseInstallationServlet servlet = new LicenseInstallationServlet();
servlet.setLicenseManager(licenseManager()); servlet.setLicenseManager(licenseManager());
servlet.setProperties(licenseProperties);
ServletRegistrationBean<LicenseInstallationServlet> registrationBean = new ServletRegistrationBean<>(servlet, "/license/install"); ServletRegistrationBean<LicenseInstallationServlet> registrationBean = new ServletRegistrationBean<>(servlet, "/license/install");
registrationBean.setMultipartConfig(new MultipartConfigElement("", 1024 * 1024, 1024 * 1024, 1024 * 1024)); registrationBean.setMultipartConfig(new MultipartConfigElement("", 1024 * 1024, 1024 * 1024, 1024 * 1024));
return registrationBean; return registrationBean;
......
...@@ -24,12 +24,15 @@ public class LicenseInstallationServlet extends HttpServlet { ...@@ -24,12 +24,15 @@ public class LicenseInstallationServlet extends HttpServlet {
@Setter @Setter
private LicenseManager licenseManager; private LicenseManager licenseManager;
@Setter
private LicenseProperties properties;
@Override @Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Part filePart = req.getPart("license"); Part filePart = req.getPart("license");
String fileName = filePart.getSubmittedFileName(); String fileName = filePart.getSubmittedFileName();
try (InputStream is = filePart.getInputStream()) { try (InputStream is = filePart.getInputStream()) {
Path dest = Paths.get(fileName); Path dest = Paths.get(properties.getLocation(), fileName).toAbsolutePath().normalize();
Files.copy(is, dest, StandardCopyOption.REPLACE_EXISTING); Files.copy(is, dest, StandardCopyOption.REPLACE_EXISTING);
this.licenseManager.install(dest.toString()); this.licenseManager.install(dest.toString());
resp.setStatus(HttpStatus.OK.value()); resp.setStatus(HttpStatus.OK.value());
......
package com.tbyf.license;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
@Data
@ConfigurationProperties(prefix = "license")
public class LicenseProperties {
private String location = "/hip/license";
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment