1 通用模块
spring: profiles: include: - thymeleaf - datasource-${spring.profiles.active} - mybatis active: dev
注意:从 2.4 版本开始,Spring Boot 除了以前支持的 YAML 之外,还扩展了对属性文件的多文档文件的支持。 所以现在,我们可以在同一个 application.properties 中指定开发和生产属性:
spring.application.name=profiles_test
spring.profiles.active=first
debug=false
#---
spring.config.activate.on-profile=first
my.props.prop1=prop1 first
my.props.prop2=prop2 first
### dummy comment
#---
### dummy comment
spring.config.activate.on-profile=second
my.props.prop1=prop1 second
my.props.prop2=prop2 second
2 设置pom.xml
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<spring.profiles.active>dev</spring.profiles.active>
</properties>
</profile>
<profile>
<id>prod</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<spring.profiles.active>prod</spring.profiles.active>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<copy todir="/var/www/html/static">
<fileset dir="${basedir}/src/main/resources/static" />
</copy>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
3 规则映射
server { server_name xxx.xxx.com //规则映射 location /static/ { alias /var/www/html/static/; } location / { proxy_pass http://localhost:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
4 运行
mvn clean package -Pprod
文章评论