file.Dir变为选配置添加其默认值
This commit is contained in:
@ -1,15 +1,23 @@
|
||||
package cn.keking.config;
|
||||
|
||||
import org.artofsolving.jodconverter.office.OfficeUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @auther: chenjh
|
||||
* @time: 2019/4/10 17:22
|
||||
* @description
|
||||
*/
|
||||
@Component
|
||||
public class ConfigConstants {
|
||||
|
||||
private static String[] simText = {};
|
||||
private static String[] media = {};
|
||||
private static String convertedFileCharset;
|
||||
private static String fileDir = OfficeUtils.getHomePath() + File.separator + "file" + File.separator;
|
||||
|
||||
public static String[] getSimText() {
|
||||
return simText;
|
||||
@ -35,4 +43,18 @@ public class ConfigConstants {
|
||||
ConfigConstants.convertedFileCharset = convertedFileCharset;
|
||||
}
|
||||
|
||||
public static String getFileDir() {
|
||||
return fileDir;
|
||||
}
|
||||
|
||||
@Value("${file.dir:default}")
|
||||
public void setFileDir(String fileDir) {
|
||||
if (!"default".equals(fileDir)) {
|
||||
if (!fileDir.endsWith(File.separator)) {
|
||||
fileDir = fileDir + File.separator;
|
||||
}
|
||||
ConfigConstants.fileDir = fileDir;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
package cn.keking.config;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
/**
|
||||
* @auther: chenjh
|
||||
* @time: 2019/4/16 20:04
|
||||
* @description
|
||||
*/
|
||||
@Configuration
|
||||
public class WebConfig extends WebMvcConfigurerAdapter {
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(WebConfig.class);
|
||||
/**
|
||||
* 访问外部文件配置
|
||||
*/
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
String filePath = ConfigConstants.getFileDir();
|
||||
LOGGER.info("Add resource locations: {}", filePath);
|
||||
registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/","classpath:/resources/","classpath:/static/","classpath:/public/","file:" + filePath);
|
||||
super.addResourceHandlers(registry);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user