lxw
2023-05-25 f3c27fb78447449a950ba73c5e72ceda64ad8a12
src/main/java/com/whyc/App.java
@@ -1,9 +1,16 @@
package com.whyc;
import org.apache.catalina.connector.Connector;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@@ -14,12 +21,35 @@
 **/
@SpringBootApplication
@EnableWebMvc
@ServletComponentScan(basePackages = {"com.whyc.filter","com.whyc.servlet"})
@ServletComponentScan(basePackages = {"com.whyc.filter","com.whyc.servlet","com.whyc.listener"})
@EnableCaching
public class App extends WebMvcConfigurerAdapter  implements WebMvcConfigurer {
    public static void main(String[] args) {
        SpringApplication.run(App.class,args);
        SpringApplication.run(App.class, args);
    }
    @Value("${http.port}")
    private Integer httpPort;
    @Bean
    @ConditionalOnProperty(prefix = "spring.profiles",name = "active",havingValue = "prod-ssl")
    public ServletWebServerFactory servletContainer() {
        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
        // 添加http
        tomcat.addAdditionalTomcatConnectors(createStandardConnector());
        return tomcat;
    }
    /**
     * 配置http
     *
     * @return connector
     */
    private Connector createStandardConnector() {
        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
        connector.setPort(httpPort);
        return connector;
    }
}