Spring Boot啓動程序一般使用Tomcat做爲默認的嵌入式服務器。若是須要更改 - 您能夠排除Tomcat依賴項並改成包含Jetty或Undertow:java
jetty配置:web
<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>
@Bean public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory() { JettyEmbeddedServletContainerFactory jettyContainer = new JettyEmbeddedServletContainerFactory(); jettyContainer.setPort(9000); jettyContainer.setContextPath("/springbootapp"); return jettyContainer; }
undertow配置:spring
<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-undertow</artifactId> </dependency>
@Bean public UndertowEmbeddedServletContainerFactory embeddedServletContainerFactory() { UndertowEmbeddedServletContainerFactory factory = new UndertowEmbeddedServletContainerFactory(); factory.addBuilderCustomizers(new UndertowBuilderCustomizer() { @Override public void customize(io.undertow.Undertow.Builder builder) { builder.addHttpListener(8080, "0.0.0.0"); } }); return factory; }
Spring Boot啓動程序一般使用Tomcat做爲默認的嵌入式服務器。若是須要更改 - 您能夠排除Tomcat依賴項並改成包含Jetty或Undertow:tomcat
配置Jettyspringboot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<
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
>
|
1
2
3
4
5
6
7
8
9
|
@Bean
public
JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory() {
JettyEmbeddedServletContainerFactory jettyContainer =
new
JettyEmbeddedServletContainerFactory();
jettyContainer.setPort(
9000
);
jettyContainer.setContextPath(
"/springbootapp"
);
return
jettyContainer;
}
|
配置Undertow服務器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<
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-undertow</
artifactId
>
</
dependency
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
@Bean
public
UndertowEmbeddedServletContainerFactory embeddedServletContainerFactory() {
UndertowEmbeddedServletContainerFactory factory =
new
UndertowEmbeddedServletContainerFactory();
factory.addBuilderCustomizers(
new
UndertowBuilderCustomizer() {
@Override
public
void
customize(io.undertow.Undertow.Builder builder) {
builder.addHttpListener(
8080
,
"0.0.0.0"
);
}
});
return
factory;
}
|