惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Security Archives - TechRepublic
Security Archives - TechRepublic
博客园 - 三生石上(FineUI控件)
云风的 BLOG
云风的 BLOG
C
Check Point Blog
Engineering at Meta
Engineering at Meta
Y
Y Combinator Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Forbes - Security
Forbes - Security
IT之家
IT之家
L
LINUX DO - 最新话题
N
News and Events Feed by Topic
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
雷峰网
雷峰网
N
News | PayPal Newsroom
The Last Watchdog
The Last Watchdog
V
Visual Studio Blog
月光博客
月光博客
Microsoft Azure Blog
Microsoft Azure Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Webroot Blog
Webroot Blog
TaoSecurity Blog
TaoSecurity Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Schneier on Security
Schneier on Security
P
Privacy International News Feed
G
Google Developers Blog
博客园 - 聂微东
博客园 - 叶小钗
M
MIT News - Artificial intelligence
Apple Machine Learning Research
Apple Machine Learning Research
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
WordPress大学
WordPress大学
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Simon Willison's Weblog
Simon Willison's Weblog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
宝玉的分享
宝玉的分享
H
Hacker News: Front Page
Martin Fowler
Martin Fowler
L
Lohrmann on Cybersecurity
G
GRAHAM CLULEY
酷 壳 – CoolShell
酷 壳 – CoolShell
罗磊的独立博客
T
The Exploit Database - CXSecurity.com
S
Security @ Cisco Blogs
博客园_首页
AWS News Blog
AWS News Blog
P
Proofpoint News Feed
人人都是产品经理
人人都是产品经理
Help Net Security
Help Net Security
Google DeepMind News
Google DeepMind News
T
Threatpost

博客园 - 倾听-静轩水月

Mysql优化笔记 Arthas使用 vue2.0和vue3.0同时使用 零基础尝试mybatis-plus读写分离 零基础尝试搭建docker和nacos环境 零基础尝试mysql主从复制 mybatis-plus 批量插入示例 找回windows应用商店 linux 开放端口 小白零基础在 Centos 7 中安装 mysql 内存不够导致编译报错:Information:java: java.lang.OutOfMemoryError: GC overhead limit exceeded docker常用命令 CentOS7使用命令行安装Oracle11GR2 使用Xshell连接VMware上的Linux虚拟机 mysql免安装版初次使用 微信小程序支付证书及SSL证书使用 SqlServer无备份下误删数据恢复 javaweb学习--javabean javaweb学习--jsp
http转向https
倾听-静轩水月 · 2023-01-08 · via 博客园 - 倾听-静轩水月

很多时候我们在地址栏输入的是http,但是会自动转向到https,要实现这个功能,我们需要配置TomcatServletWebServerFactory 书上讲的是 EmbeddedServletContainerFactory, 但是现在已经不用了。
直接贴代码吧,我也是代码上试验的

 1 @Bean
 2 public TomcatServletWebServerFactory servletContainer() {
 3     TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
 4         @Override
 5         protected void postProcessContext(Context context) {
 6             SecurityConstraint securityConstant = new SecurityConstraint();
 7             securityConstant.setUserConstraint("CONFIDENTIAL");
 8             SecurityCollection securityCollection = new SecurityCollection();
 9             securityCollection.addPattern("/*");
10             securityConstant.addCollection(securityCollection);
11             context.addConstraint(securityConstant);
12         }
13     };
14 
15     tomcat.addAdditionalTomcatConnectors(httpConnector());
16     return tomcat;
17 }
18 
19 @Bean
20 public Connector httpConnector() {
21     Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
22     connector.setScheme("http");
23     connector.setPort(8080);
24     connector.setSecure(false);
25     connector.setRedirectPort(8443);
26     return connector;
27 }

此时访问 http://localhost:8080 就会自动转到 https://localhost:8443