开发微信小程序时,小程序请求后台报出了
java.lang.UnsatisfiedLinkError: org.apache.tomcat.jni.SSL.renegotiatePending(J)I我的springboot版本是2.1.1.RELEASE,经过查阅发现2.1.1版本及其以上的内置的tomcat的版本都是9.0.13的,虽然我也不清楚为什么配置Https他要报出这个错,但是还是要解决这个问题。
一、
在pom.xml中加入
<properties> <tomcat.version>9.0.12</tomcat.version></properties><dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-juli</artifactId> <version>${tomcat.version}</version></dependency>然后更新maven
二、
resources文件夹下加入SSL密钥文件
application.properties中加入
server.ssl.key-store = classpath:*************.jks server.ssl.key-store-password = ******* server.ssl.key-password = *********** 代表自己文件的信息
三、
启动类中加入
@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(8080); connector.setSecure(false); // 监听到http的端口号后转向到的https的端口号 connector.setRedirectPort(8888); return connector; }然后debug启动,完成。













