SpringBoot启动Tomcat报错LibraryNotFoundError,Can't load library:tcnative-1.dll

来源于  https://blog.csdn.net/testcs_dn/article/details/86309819

 

环境:Windows10-64位,SpringCloud是最新的Greenwich.RC2,SpringBoot是2.1.1,内嵌Tomcat 9.0.13,

最近搭建的SpringCloud项目,把日志级别设为Debug后,从控制台看到启动时tomcat报无法找到JNI动态链接库的错误,完整的异常栈信息如下:

org.apache.tomcat.jni.LibraryNotFoundError: Can't load library: D:\xxx\bin\tcnative-1.dll, Can't load library: D:\xxx\bin\libtcnative-1.dll, no tcnative-1 in java.library.path, no libtcnative-1 in java.library.path
at org.apache.tomcat.jni.Library.<init>(Library.java:102) ~[tomcat-embed-core-9.0.13.jar:9.0.13]
at org.apache.tomcat.jni.Library.initialize(Library.java:206) ~[tomcat-embed-core-9.0.13.jar:9.0.13]
at org.apache.catalina.core.AprLifecycleListener.init(AprLifecycleListener.java:198) [tomcat-embed-core-9.0.13.jar:9.0.13]
at org.apache.catalina.core.AprLifecycleListener.isAprAvailable(AprLifecycleListener.java:107) [tomcat-embed-core-9.0.13.jar:9.0.13]
at org.apache.catalina.connector.Connector.<init>(Connector.java:80) [tomcat-embed-core-9.0.13.jar:9.0.13]
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:164) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:181) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:154) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540) [spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at cc.liudun.SpringCloudDemoApplication.main(SpringCloudDemoApplication.java:21) [classes/:na]
这是因为Tomcat中的connector为了提高性能,采用了加载与操作系统绑定(非跨平台)的本地库的方式,比如Windows系统中就是.dll动态链接库。上述异常中找不到的两个.dll库文件,默认会去Tomcat的bin目录下去找,但是由于SpringBoot的Tomcat是嵌入式的,没有这两个.dll,所以只好自己去官网下载,到如下官方地址下载,并放到C:\Windows\System32\目录下:

http://archive.apache.org/dist/tomcat/tomcat-connectors/native/1.2.14/binaries/

 

posted @ 2020-03-11 10:54  苦行者的刀  阅读(5087)  评论(0编辑  收藏  举报