Spring Boot中以文件方式配置Tomcat

一 点睛

Tomcat属性配置文件在下D:\.m2\repos\org\springframework\boot\spring-boot-autoconfigure\1.3.7.RELEASE\spring-boot-autoconfigure-1.3.7.RELEASE-sources\org\springframework\boot\autoconfigure\web文件夹的ServerProperties配置类中定义,我们只需要在application.properties配置属性做配置即可。通用的Servlet容器配置都以"server"作为前置,而Tomcat特有配置以"server.tomcat"作为前缀。

二 相关代码解读

@ConfigurationProperties(prefix = "server", ignoreUnknownFields = true)
public class ServerProperties
        implements EmbeddedServletContainerCustomizer, EnvironmentAware, Ordered {

    //配置程序端口
    private Integer port;

    //配置绑定的IP
    private InetAddress address;

    //配置访问路径
    private String contextPath;


    private String displayName = "application";

    @NestedConfigurationProperty
    private ErrorProperties error = new ErrorProperties();

    @NotNull
    private String servletPath = "/";

    private final Map contextParameters = new HashMap();

    private Boolean useForwardHeaders;


    private String serverHeader;

    private Session session = new Session();

    @NestedConfigurationProperty
    private Ssl ssl;

    //配置压缩
    @NestedConfigurationProperty
    private Compression compression = new Compression();

    @NestedConfigurationProperty
    private JspServlet jspServlet;

    //配置Tomcat
    private final Tomcat tomcat = new Tomcat();

    //配置Jetty
    private final Jetty jetty = new Jetty();

    //配置Undertow
    private final Undertow undertow = new Undertow();
    ......
}

三 配置方法

配置Servlet

server.port= #配置程序端口,默认为8080
server.session-timeout= #用户会话session过期时间,以秒为单位
server.context-path=#配置访问路径,默认为/

配置Tomcat

server.tomcat.uri-encoding=#配置tomcat的编码,默认为UTF-8
server.tomcat.compression=#Tomcat是否开启压缩,默认为关闭

 

 

你可能感兴趣的:(Spring,Boot)