springboot如何设置域名访问

时间:2024-10-15 14:19:59

1、Spring Boot将容器内置后,它通过配置文件的方式类修改相关server配置。 先看一下下面的图,为关于server的配置列项:

springboot如何设置域名访问

2、其中常用的配置只有少数几个,已经用紫色标记起来。红框圈起来的部分,看名称分类就可以明白其作用。 对server的几个常用的配置做个简单说明:# 项目contextPath,一般在正式发布版本中,我们不配置server.context-path=/myspringboot# 错误页,指定发生错误时,跳转的URL。请查看BasicErrorController源码便知server.error.path=/error# 服务端口server.port=9090# session最大超时时间(分钟),默认为30

springboot如何设置域名访问

3、Tomcat Tomcat为Spring Boot的默认容器,下面是几个常用配置:# tomcat最大线程数,默认为200server.tomcat.max-threads=800# tomcat的URI编码server.tomcat.uri-encoding=UTF-8# 存放Tomcat的日志、Dump等文件的临时文件夹,默认为系统的tmp文件夹(如:C:\Users\Shanhy\AppData\Local\Temp)server.tomcat.basedir=H:/springboot-tomcat-tmp# 打开Tomcat的Access日志,并可以设置日志格式的方法

springboot如何设置域名访问

4、Jetty 如果你要选择Jetty,也非常简单,就是把pom中的tomcat依赖排除,并加入Jetty容器的依赖,如下:<d髫潋啜缅ependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jetty</artifactId> </dependency><dependencies>

springboot如何设置域名访问

5、打包 打包方法: CMD进入项目目录,使用 mvn clean package 命令打包,以我的项目工程为例:E:\spring-boot-sample>mvn clean package

springboot如何设置域名访问

6、可以追加参数 -Dmaven.test.skip=true 跳过测试。 打包后的文件存放于项目下的target目录中,如:spring-boot-sample-0.0.1-SNAPSHOT.jar 如果pom配置的是war包,则为spring-boot-sample-0.0.1-SNAPSHOT.war

springboot如何设置域名访问
© 手抄报圈