springboot(⼋)内置tomcat配置和优化⼀、
在application.properties⽂件中配置
#配置tomcat端⼝,针对内置的tomcat
servlet和tomcat的关系#server.port=8888
#绑定ip地址,只能由设置的地址进⼊访问
#server.address=172.0.0.1
#配置context-path,访问时,需要在连接后加上配置的路径 localhost:8888/server
#t-path=/server
⼆、实现 WebServerFactoryCustomizer 接⼝
1、
@Component
public class TomcatCfig implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
@Override
public void customize(ConfigurableServletWebServerFactory factory) {
factory.setContextPath("/demo");
factory.setPort(8090);
}
}
2、
WebServerFactoryCustomizer⾥⾯绑定 TomcatServletWebServerFactory 可以设置tomcat BIO / NIO(Tomcat7之后采⽤的默认NIO,)设置连接器 Connector
@Component
public class TomcatCfig implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
@Override
public void customize(TomcatServletWebServerFactory factory) {
factory.setContextPath("/demo");
factory.setPort(8090);
}
}
同时springboot⽀持jetty
pom⽂件要加⼊下⾯注⼊来去除springboot 中默认的Tomcat 依赖
<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>
@Component//启动jetty
public class Jetty implements WebServerFactoryCustomizer<JettyServletWebServerFactory> {
@Override
public void customize(JettyServletWebServerFactory factory) {
System.out.println("jetty================");
factory.setContextPath("/demo");
factory.setPort(8090);
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论