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的视图

阅读 5.4k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题