在Spring Boot上将HTTP重定向到HTTPS-(Wildfly服务器)

时间:2020-05-22 12:13:28

标签: java spring spring-boot tomcat wildfly

我想在Wildlfy上部署一个Spring Boot应用程序,该应用程序可以将Http请求重定向到Https。

这是application.properties:

server.port=8443
server.ssl.key-alias=https-example
server.ssl.key-password=password
server.ssl.key-store=classpath:https-example.jks
server.ssl.key-store-provider=SUN
server.ssl.key-store-type=JKS

ServerConfig类:

import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

public class ServerConfig {
    @Bean
    public ServletWebServerFactory 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(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
        connector.setScheme("http");
        connector.setPort(8080);
        connector.setSecure(false);
        connector.setRedirectPort(8443);
        return connector;
    }
}

我将Spring Boot应用程序构建为war,当我尝试在Wildfly上部署它时,出现以下错误:

{"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"demo.war\".undertow-deployment" => "java.lang.RuntimeException: java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration.propertySourcesPlaceholderConfigurer
    Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration.propertySourcesPlaceholderConfigurer
    Caused by: java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration.propertySourcesPlaceholderConfigurer
    Caused by: java.lang.IllegalStateException: Failed to introspect Class [com.example.demo.congif.ServerConfig] from ClassLoader [ModuleClassLoader for Module \"deployment.demo.war\" from Service Module Loader]
    Caused by: java.lang.NoClassDefFoundError: org/apache/catalina/connector/Connector
    Caused by: java.lang.ClassNotFoundException: org.apache.catalina.connector.Connector from [Module \"deployment.demo.war\" from Service Module Loader]"}}`

当我阅读上面的错误日志时,我仅有的线索是它可能与tomcat有某种冲突,但是我不知道如何解决。有人可以帮忙吗?

0 个答案:

没有答案