SpringBoot----开发环境/测试环境和生产环境
application.properties是SpringBoot默认加载的,全局配置,则全部放在这里,假如有需要不同环境,配置不同的参数,比如日志、数据源,则放在不同的properties文件下面,在application.properties上面配置一句话即可:
## 开发/测试/生产环境分别对应dev/test/prod
spring.profiles.active=dev
spring boot 静态资源(html/js等文件)
在/src/main/resources目录下增加static目录(默认路径)
http://127.0.0.1:8080/task/500.html 直接访问(不加static。。)
templates路径需要配置(这是后台跳前端页面)
http://127.0.0.1:8080/task/hello.html 访问(发现hello.html是和hello.do一样请求)
application-dev.properties中添加:
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false
spring banner 彩蛋生成器:
http://patorjk.com/software/taag/#p=display&f=Graffiti&t=222%0A
IDEA 好用的插件:
https://blog.csdn.net/xlgen157387/article/details/78970079
spring boot 启动
1、nohup java -jar spring-boot01-1.0-SNAPSHOT.jar > log.file 2>&1 &
这种情况适合在生产环境长时间运行。
注意
mvn clean package -Dmaven.test.skip=true
1,在使用mvn package进行编译、打包时,Maven会执行src/test/java中的JUnit测试用例,有时为了跳过测试,会使用参数-DskipTests和-Dmaven.test.skip=true,这两个参数的主要区别是:
-DskipTests,不执行测试用例,但编译测试用例类生成相应的class文件至target/test-classes下。
-Dmaven.test.skip=true,不执行测试用例,也不编译测试用例类。
SSL with secure
server:
port: 8081
servlet:
context-path: /nonoscore
session:
cookie:
http-only: true
secure: true
tomcat:
protocol-header: X-Forwarded-Proto
remote-ip-header: X-Forwarded-For
不让null值返回前端
import com.fasterxml.jackson.annotation.JsonInclude;
@JsonInclude(JsonInclude.Include.NON_NULL)
只能有一个main方法
代码中只能有一个main方法,不然在通过mvn package命令打包的时候,总是出错就报了个错误
错误详细内容是:
- Caused by: java.lang.IllegalStateException: Unable to find a single main class f
- rom the following candidates [com.example.app.App, com.example.app.controller.Te
- stPropertiesController]
maven打包排除某个目录
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<packagingExcludes>
WEB-INF/classes/com/zjaisino/base/rpc/controller/testcase/*.*
</packagingExcludes>
</configuration>
</plugin>