springboot实现https协议

springboot项目 是用springboot启动的 没有用铝tomcat 现在要配置https访问 现在
我用http访问可以跳转成https访问 但是项目报错

 java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens
    at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:422) ~[tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:683) ~[tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861) [tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455) [tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.15.jar:8.5.15]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_152]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_152]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.15.jar:8.5.15]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_152]

我的配置

 server:
  port: 8080
#    context-path: /iuhao
  server.ssl.key-store: tomcat.keystore
  server.ssl.key-store-password: 123456
  server.ssl.keyStoreType: JKS
  server.ssl.keyAlias: tomcat
keytool:
  genkey:
    alias: tomcat #(别名)
    keypass: 123456 #(别名密码)
    keyalg: RSA #(生证书的算法名称,RSA是一种非对称加密算法)
    keysize: 1024 #(密钥长度,证书大小)
    validity: 365 #(证书有效期,天单位)
    keystore: E:/tomcat.keystore #(指定生成证书的位置和证书名称)
    storepass: 123456 #(获取keystore信息的密码)
    storetype: storetype #(指定密钥仓库类型)

然后是代码

 @Configuration
@EnableTransactionManagement
@SpringBootApplication
@Import({InitServiceConfiguration.class, InitConfiguration.class})
@ComponentScan("com.bonpoint")
public class AppApiApplication {

    public static void main(String[] args) {
        SpringApplication.run(AppApiApplication.class, args);
    }

    /**
     * 文件上传配置
     * @return
     */
//    @Bean
//    public MultipartConfigElement multipartConfigElement() {
//        MultipartConfigFactory factory = new MultipartConfigFactory();
//        //文件最大
//        factory.setMaxFileSize("10240MB"); //KB,MB
//        /// 设置总上传数据总大小
//        factory.setMaxRequestSize("10240MB");
//        return factory.createMultipartConfig();
//    }

    /**
     * it‘s for set http url auto change to https
     */
    @Bean
    public EmbeddedServletContainerFactory servletContainer() {
        TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
            @Override
            protected void postProcessContext(Context context) {
                SecurityConstraint securityConstraint = new SecurityConstraint();
                securityConstraint.setUserConstraint("CONFIDENTIAL");// confidential
                SecurityCollection collection = new SecurityCollection();
                collection.addPattern("/*");
                securityConstraint.addCollection(collection);
                context.addConstraint(securityConstraint);
            }
        };
        tomcat.addAdditionalTomcatConnectors(httpConnector());
        return tomcat;
    }

    @Bean
    public Connector httpConnector() {
        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
        connector.setScheme("http");
        connector.setPort(80);
        connector.setSecure(false);
        connector.setRedirectPort(8080);
        return connector;
    }
}

请教一下大佬看我那里配置错了

1个回答

图片说明这是证书的位置

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问