springboot内嵌了tomcat容器,可以通过3中方式来修改tomcat。
(1)修改application.properties文件中属性,比如:
server.port=8081 server.address=127.0.0.1 server.tomcat.accesslog.enabled=true server.tomcat.accesslog.directory=d\:/springboot/logs
端口:8081
绑定IP:上面的配置只能在浏览器输入localhost:8081或者127.0.0.1访问
启动tomcat的访问日志
tomcat访问日志的路径:D:\springboot\logs\access_log.2019-12-05.log,(2019-12-05是运行时间)
其他配置可以看源码:org.springframework.boot.autoconfigure.web.ServerProperties
(2)实现WebServerFactoryCustomizer接口,并装配到spring容器中,如下:
pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.edu.spring</groupId> <artifactId>springboot_web</artifactId> <version>1.0.0</version> <name>springboot_web</name> <!-- FIXME change it to the project's website --> <url>http://www.example.com</url> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.4.RELEASE</version> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> </project>