SpringBoot 配置了SSL证书后,访问不了了,怎么解决?

微信图片编辑_20200330103806.jpg

这个是我的.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的视图

以上是 SpringBoot 配置了SSL证书后,访问不了了,怎么解决? 的全部内容, 来源链接: utcz.com/a/166893.html

回到顶部