项目打成war包部署
parent
d3e4646977
commit
d35ae04832
@ -0,0 +1,12 @@
|
|||||||
|
package com.shxy.xymanager_admin;
|
||||||
|
|
||||||
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||||
|
|
||||||
|
public class SpringBootStartApplication extends SpringBootServletInitializer {
|
||||||
|
@Override
|
||||||
|
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
|
||||||
|
// 注意这里要指向原先用main方法执行的Application启动类
|
||||||
|
return builder.sources(XymanagerAdminApplication.class);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
org.springframework.boot.env.EnvironmentPostProcessor=com.shxy.xymanager_framework.config.MyEnvironmentPostProcessor
|
@ -0,0 +1,52 @@
|
|||||||
|
package com.shxy.xymanager_framework.config;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||||
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
|
import org.springframework.core.env.MutablePropertySources;
|
||||||
|
import org.springframework.core.env.PropertiesPropertySource;
|
||||||
|
import org.springframework.core.io.FileSystemResource;
|
||||||
|
import org.springframework.core.io.support.PropertiesLoaderUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class MyEnvironmentPostProcessor implements EnvironmentPostProcessor {
|
||||||
|
@Override
|
||||||
|
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||||
|
//tomcat路径
|
||||||
|
String property = System.getProperty("catalina.home");
|
||||||
|
System.out.println("catalinahome:"+property);
|
||||||
|
|
||||||
|
String path =property+ File.separator+"conf"+File.separator+"application.yml";
|
||||||
|
|
||||||
|
//Springboot读取yml配置
|
||||||
|
YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
|
||||||
|
yaml.setResources(new FileSystemResource(path));
|
||||||
|
MutablePropertySources propertySources = environment.getPropertySources();
|
||||||
|
propertySources.addFirst(new PropertiesPropertySource("Config", yaml.getObject()));
|
||||||
|
|
||||||
|
|
||||||
|
// File file = new File(path);
|
||||||
|
// System.out.println("Loading local settings from : "+path);
|
||||||
|
//
|
||||||
|
// if (file.exists()) {
|
||||||
|
// MutablePropertySources propertySources = environment.getPropertySources();
|
||||||
|
// Properties properties = loadProperties(file);
|
||||||
|
// System.out.println(properties.toString());
|
||||||
|
// propertySources.addFirst(new PropertiesPropertySource("Config", properties));
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
// private Properties loadProperties(File f) {
|
||||||
|
// FileSystemResource resource = new FileSystemResource(f);
|
||||||
|
// try {
|
||||||
|
// return PropertiesLoaderUtils.loadProperties(resource);
|
||||||
|
// } catch (IOException ex) {
|
||||||
|
// throw new IllegalStateException("Failed to load local settings from " + f.getAbsolutePath(), ex);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
Loading…
Reference in New Issue