项目打成war包部署

master
liuguijing 2 years ago
parent d3e4646977
commit d35ae04832

@ -12,6 +12,8 @@
<version>1.0.0</version>
<name>xymanager_admin</name>
<description>Demo project for Spring Boot</description>
<packaging>war</packaging>
<properties>
<java.version>1.8</java.version>
</properties>
@ -71,7 +73,28 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<!--打包时排除src/main/resources下的所有以.properties .yml .xml为后缀的配置文件-->
<excludes>
<exclude>**/*.properties</exclude>
<exclude>**/*.yml</exclude>
<!-- <exclude>**/*.xml</exclude>-->
</excludes>
</resource>
</resources>
<finalName>xymanager-admin</finalName>
</build>

@ -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);
}
}

@ -5,7 +5,9 @@ import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
@ -17,7 +19,7 @@ import org.springframework.core.env.Environment;
@Slf4j
@EnableConfigurationProperties
@ComponentScan(basePackages = {"com.shxy"})
public class XymanagerAdminApplication {
public class XymanagerAdminApplication {
public static void main(String[] args) {
try {

@ -0,0 +1 @@
org.springframework.boot.env.EnvironmentPostProcessor=com.shxy.xymanager_framework.config.MyEnvironmentPostProcessor

@ -40,6 +40,11 @@
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
@ -73,6 +78,14 @@
</dependency>
<!--打war包引入的下面依赖-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.shxy</groupId>
<artifactId>xymanager_common</artifactId>

@ -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…
Cancel
Save