SpringBoot 配置了SSL证书后,访问不了了,怎么解决?
这个是我的.yml配置
@Configuration
public class HttpToHttpsConfig {
@Bean
public TomcatServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(Context context) {
SecurityConstraint constraint = new SecurityConstraint();
constraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
constraint.addCollection(collection);
context.addConstraint(constraint);
}
};
tomcat.addAdditionalTomcatConnectors(httpConnector());
return tomcat;
}
@Bean
public Connector httpConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
// Connector监听的http的端口号
connector.setPort(8080);
connector.setSecure(false);
// 监听到http的端口号后转向到的https的端口号
connector.setRedirectPort(443);
return connector;
}
}
项目能成功启动
Tomcat started on port(s): 443 (https) 8080 (http) with context path ''
2020-03-30 10:40:24.176 INFO 2792 --- [ main] com.demo.DemoApplication : Started DemoApplication in 2.292 seconds (JVM running for 3.045)
但是输入 http://localhost:8080/admin/index 或 https://localhost:8080/admin/index 都访问不了,因为我做了登录校验,没登录会跳去/login,所以控制台报解析不了/login的视图
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论