springboot 2 修改端口号
springboot 废弃了EmbeddedServletContainerCustomizer ,修改端口,从官方文档上看到的方法,
1
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.stereotype.Component; @Component
public class CustomizationBean implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> { @Override
public void customize(ConfigurableServletWebServerFactory server) {
server.setPort(9000);
} }
2
@Bean
public ConfigurableServletWebServerFactory webServerFactory() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.setPort(9000);
factory.setSessionTimeout(10, TimeUnit.MINUTES);
factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/notfound.html"));
return factory;
}
3
75.13 Enable Multiple Connectors with Tomcat
You can add an org.apache.catalina.connector.Connector to the TomcatServletWebServerFactory, which can allow multiple connectors, including HTTP and HTTPS connectors, as shown in the following example:
@Bean
public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
tomcat.addAdditionalTomcatConnectors(createSslConnector());
return tomcat;
} private Connector createSslConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
try {
File keystore = new ClassPathResource("keystore").getFile();
File truststore = new ClassPathResource("keystore").getFile();
connector.setScheme("https");
connector.setSecure(true);
connector.setPort(8443);
protocol.setSSLEnabled(true);
protocol.setKeystoreFile(keystore.getAbsolutePath());
protocol.setKeystorePass("changeit");
protocol.setTruststoreFile(truststore.getAbsolutePath());
protocol.setTruststorePass("changeit");
protocol.setKeyAlias("apitester");
return connector;
}
catch (IOException ex) {
throw new IllegalStateException("can't access keystore: [" + "keystore"
+ "] or truststore: [" + "keystore" + "]", ex);
}
}
个人比较喜欢第二种方法。
真的是和1 的变化太大,踩了好多的坑
如果要在application.properties 修改端口号,很简单,只需要写上
server.port= 端口号,就可以了
springboot 2 修改端口号的更多相关文章
- 5、springboot之修改端口号
在resources中加入application.properties文件,里面加入 servier.port = 端口号 访问的时候,就用localhost:端口号 完事
- windows下安装mysql数据库修改端口号
Window版本 卸载原本的mysql sc delete MySQL //删除mysql 1.下载 1 2 3 MySQL https://dev.mysql.com/downloads/ins ...
- mysql:赋予用户权限、查看及修改端口号
一.mysql 赋给用户权限 grant all privileges on *.* to joe@localhost identified by '1'; flush privileges; 即用u ...
- 团队项目系列博客 —— 在路上(之wampserver 修改根目录以及配置多站点以及修改端口号)
团队项目系列博客 -- 在路上(之wampserver 修改根目录以及配置多站点以及修改端口号) 标签(空格分隔): wampserver php 参考:参考文献1.慕课网.知乎.github 一.w ...
- 【Spring Boot学习之七】自定义参数&多环境配置&修改端口号&yml
环境 eclipse 4.7 jdk 1.8 Spring Boot 1.5.2 一.自定义参数通过注解直接获取配置文件application.properties中配置key的value1.appl ...
- SVN server 服务端修改端口号
SVN server 服务端修改端口号 在实际使用中可能当安装svn server 服务后,发现与后续其他程序端口冲突, 1.打开svn server 管理界面->操作->properti ...
- linux mysql 查看默认端口号和修改端口号
如何查看mysql 默认端口号和修改端口号 2015-03-19 17:42:18 1. 登录mysql [root@test /]# mysql -u root -p Enter password: ...
- Tomcat服务器的下载与安装,修改端口号
安装及简单配置Tomcat服务器: 1.登录www.apache.org 网站,之后点击Projects , 点击Project List,找到Tomcat. 2.点击Tomcat之后,之后进入Tom ...
- webstorm 修改端口号
webstorm 修改端口号: 至此,点击下方 [apply],端口号修改完成.
随机推荐
- SpringDataJPA在Entity中常用的注解浅析
首先我们常用的注解包括(@Entity.@Table.@Id.@IdClass.@GeneratedValue.@Basic.@Transient.@Column.@Temporal.@Enumera ...
- Idea jsp页面乱码
jsp页面中添加 <%@ page language="java" contentType="text/html; charset=utf-8" page ...
- Windows route
ROUTE [-f] [-p] [-4|-6] command [destination] [MASK netmask] [gateway] [METRIC met ...
- python queue, pipe, manage
线程中的Queue import time import threading import queue import random def putMessage(): for i in "H ...
- day10 nfs服务,nginx负载均衡,定时任务
==================nginx 负载均衡==================== 实现nginx负载均衡的效果,并运用nfs服务共享目录,使所有nginx服务拥有共同的http目录 n ...
- JS 内置对象 String对象
JS内置对象 String对象:字符串对象,提供了对字符串进行操作的属性和方法. Array对象:数组对象,提供了数组操作方面的属性和方法. Date对象:日期时间对象,可以获取系统的日期 ...
- vue打包后index.html界面报错
vue项目完成后,打包放到服务器上,打开index.html页面时发现一片空白并且报错 很明显是js和css引用不到. 解决办法: 修改vue项目config文件夹下面的index.js,将asset ...
- P1417 烹调方案 /// DP(假设 简化公式 排序)
题目大意: https://www.luogu.org/problemnew/show/P1417 题解 看第一份方法的公式 排序后01背包 #include <bits/stdc++.h> ...
- Python全栈开发:configparser模块
#!/usr/bin/env python # -*- coding;utf-8 -*- import configparser # 创建对象 conn = configparser.ConfigPa ...
- C++ 系列:C++ 内存布局
1 前言 了解你所使用的编程语言究竟是如何实现的,对于C++程序员可能特别有意义.首先,它可以去除我们对于所使用语言的神秘感,使我们不至于对于编译器干的活感到完全不可思议:尤其重要的是,它使我们在De ...