EmbeddedWebServerFactoryCustomizerAutoConfiguration
参考SpringBoot——嵌入式Servlet容器自动配置原理
我们在项目栏->External Libraries->...autoconfigure里找到spring.factories
其中提到了EmbeddedWebServerFactoryCustomizerAutoConfiguration
该类中有三个方法:xxxCustomizerConfiguration,这三个方法中都有一个注解
@ConditionalOnClass
,该注解中标明在引入哪些依赖时就会使相应的XxxCustomizerConfiguration生效,这也是通过修改依赖就可将Servlet容器切换为Tomcat、Jetty和Undertow的原因.
ServletWebServerFactoryAutoConfiguration
在刚才的spring.factories里同样有ServletWebServerFactoryAutoConfiguration
...
@EnableConfigurationProperties(ServerProperties.class)
public class ServletWebServerFactoryAutoConfiguration {
...
}
@EnableConfigurationProperties
开启ServerProperties
类的属性值配置。而这个类里面包含的就是Web服务的配置
@ConfigurationProperties(prefix = "server", ignoreUnknownFields = true)
public class ServerProperties {
/**
* Server HTTP port.
*/
private Integer port;
/**
* Network address to which the server should bind.
*/
private InetAddress address;
...
后者会从application.properties读取配置。
网友评论