Commit 60560651 by hy

添加LicenseProperties

parent b3a26a6f
......@@ -3,6 +3,7 @@ package com.tbyf.license;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
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.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
......@@ -10,6 +11,7 @@ import org.springframework.core.Ordered;
import javax.servlet.MultipartConfigElement;
@EnableConfigurationProperties(LicenseProperties.class)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@AutoConfiguration(after = {DispatcherServletAutoConfiguration.class})
public class LicenseAutoConfiguration {
......@@ -30,9 +32,10 @@ public class LicenseAutoConfiguration {
}
@Bean
public ServletRegistrationBean<LicenseInstallationServlet> licenseServlet() {
public ServletRegistrationBean<LicenseInstallationServlet> licenseServlet(LicenseProperties licenseProperties) {
LicenseInstallationServlet servlet = new LicenseInstallationServlet();
servlet.setLicenseManager(licenseManager());
servlet.setProperties(licenseProperties);
ServletRegistrationBean<LicenseInstallationServlet> registrationBean = new ServletRegistrationBean<>(servlet, "/license/install");
registrationBean.setMultipartConfig(new MultipartConfigElement("", 1024 * 1024, 1024 * 1024, 1024 * 1024));
return registrationBean;
......
......@@ -24,12 +24,15 @@ public class LicenseInstallationServlet extends HttpServlet {
@Setter
private LicenseManager licenseManager;
@Setter
private LicenseProperties properties;
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Part filePart = req.getPart("license");
String fileName = filePart.getSubmittedFileName();
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);
this.licenseManager.install(dest.toString());
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