SpringBoot——嵌入式Servlet容器配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/rubulai/article/details/83118553

SpringBoot默认使用Tomcat作为嵌入式的Servlet容器:

如何定制和修改Servlet容器的相关配置:
1、通过主配置文件修改和server有关的配置(ServerProperties类的属性,在低版本的SpringBoot中ServerProperties实现了EmbeddedServletContainerCustomizer接口,高版本中则没有)

server.port=8081
server.context‐path=/crud
server.tomcat.uri‐encoding=UTF‐8
//通用的Servlet容器设置
server.xxx
//Tomcat的设置
server.tomcat.xxx

2、编写一个EmbeddedServletContainerCustomizer(嵌入式的Servlet容器的定制器),来修改Servlet容器的配置:高版本的SpringBoot已不支持该方式

@Bean //一定要将这个定制器加入到容器中
public EmbeddedServletContainerCustomizer embeddedServletContainerCustomizer(){
	return new EmbeddedServletContainerCustomizer() {
		//定制嵌入式的Servlet容器相关的规则
		@Overrid
		public void customize(ConfigurableEmbeddedServletContainer container) {
			container.setPort(8083);
		}
	};
}

SpringBoot中有很多XxxCustomizer,可以通过在容器中添加相应的Customizer组件来进行定制配置

猜你喜欢

转载自blog.csdn.net/rubulai/article/details/83118553