| | |
| | | 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.web.servlet.config.annotation.EnableWebMvc; |
| | | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
| | | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; |
| | |
| | | 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; |
| | | } |
| | | |
| | | } |