Embedded ServletContainer Factory 를 찾 을 수 없 습 니까?
1614 단어 기억력 이 나 쁜 블 로그 보다 못 하 다.
다음 과 같다.
//
// http , application http.port= 80
@Value("${http.port}")
Integer httpPort;
// https 443
@Value("${server.port}")
Integer httpsPort;
// springboot2
@Bean
public TomcatServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(Context context) {
SecurityConstraint constraint = new SecurityConstraint();
constraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
constraint.addCollection(collection);
context.addConstraint(constraint);
}
};
tomcat.addAdditionalTomcatConnectors(httpConnector());
return tomcat;
}
@Bean
public Connector httpConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
//Connector http
connector.setPort(httpPort);
connector.setSecure(false);
// http https
connector.setRedirectPort(httpsPort);
return connector;
}