Javaの春を使用して、HTTPSを有効にすると問題

イーモンマック:

私はプロジェクトのために、HTTPSセキュリティを有効にする方法この短いチュートリアルを次しています。https://www.thomasvitale.com/https-spring-boot-ssl-certificate/

私はプロジェクトを実行するときしかし、私は次のエラーを取得します:

Tomcatのコネクタは、起動に失敗したポート8443でリッスンするように構成されました。ポートがすでに使用中であってもよいし、コネクタが間違って設定することができます。

チュートリアルで述べたように、私は、キーストアを生成しています。私は前が、明確な答えを上げ、この質問を見てきました。私が入力したときに私はそれを参照してくださいカントとしてポート8443は、右か何かを設定されていないnetstate -aoコマンドラインで。

すべてのすべてのヘルプは大歓迎です。

============

マイファイル

1)application.properties

spring.data.rest.base-path=/api
server.port = 8443
server.ssl.key-store-type=PKCS12
server.ssl.key-store=src/main/resources:keystore.p12
server.ssl.key-store-password=Welcome1
server.ssl.key-alias=tomcat
server.servlet.contextPath=/

2)SecurityConfig

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.requestMatchers()
        .antMatchers("/login", "/oauth/authorize")
        .and()
        .authorizeRequests()
        .anyRequest()
        //.permitAll()
        .authenticated()
        .and()
        .formLogin()
        .permitAll();
        //.httpBasic();

    http.csrf().disable();
}

/*@Bean
public PasswordEncoder passwordEncoder() {
    return new BCryptPasswordEncoder();
}*/

/*
// Create an encoder with strength 16
    BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(16);
    String result = encoder.encode("myPassword");
    assertTrue(encoder.matches("myPassword", result));
        */

@Bean
public TomcatServletWebServerFactory servletContainer() {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
        @Override
        protected void postProcessContext(Context context) {
            SecurityConstraint securityConstraint = new SecurityConstraint();
            securityConstraint.setUserConstraint("CONFIDENTIAL");
            SecurityCollection collection = new SecurityCollection();
            collection.addPattern("/*");
            securityConstraint.addCollection(collection);
            context.addConstraint(securityConstraint);
        }
    };
    tomcat.addAdditionalTomcatConnectors(getHttpConnector());
    return tomcat;
}

private Connector getHttpConnector() {
    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    connector.setScheme("http");
    connector.setPort(8080);
    connector.setSecure(false);
    connector.setRedirectPort(8443);
    return connector;
}

}

3)HelloResource

@RestController
@RequestMapping("/rest/hello")
public class HelloResource {

  @GetMapping
  public String hello(){
    return "Hello World";
  }
}
アワド:

configに443にポートを変更します。

server.port = 443

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=215263&siteId=1