首先需要去做个证书
yml配置文件中设置的是https监听端口
server: port: 10007 tomcat: basedir: /data/apps/temp #配置SSL ssl: key-store: classpath:bdcourtyard.com.jks key-store-password: 4a98pp121wv keyStoreType: JKS
以下是启动类添加的代码
/** * it‘s for set http url auto change to https */ @Bean public TomcatEmbeddedServletContainerFactory servletContainer() { TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() { @Override protected void postProcessContext(Context context) { SecurityConstraint securityConstraint = new SecurityConstraint(); securityConstraint.setUserConstraint("CONFIDENTIAL");//confidential SecurityCollection collection = new SecurityCollection(); collection.addPattern("/*"); securityConstraint.addCollection(collection); context.addConstraint(securityConstraint); } }; tomcat.addAdditionalTomcatConnectors(httpConnector()); return tomcat; } @Bean public Connector httpConnector() { Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); connector.setScheme("http"); connector.setPort(9000); connector.setSecure(true); connector.setRedirectPort(10007); return connector; }
这个是同事配的,实测有效搬过来具体自己还没研究
原文地址:https://www.cnblogs.com/heroinss/p/10509739.html
时间: 2024-10-30 08:58:44