尝试在tomcat下使用netty-tcnative-boringssl-static。当从 JUnit 测试中加载代码时,它可以正常工作,但在 tomcat 容器中却不是这样。 io.netty.handler.ssl.OpenSsl 类中的这段代码试图从 SSL 类的类加载器加载 native 库。
private static void loadTcNative() throws Exception {
String os = normalizeOs(SystemPropertyUtil.get("os.name", ""));
String arch = normalizeArch(SystemPropertyUtil.get("os.arch", ""));
Set<String> libNames = new LinkedHashSet<String>(3);
// First, try loading the platform-specific library. Platform-specific
// libraries will be available if using a tcnative uber jar.
libNames.add("netty-tcnative-" + os + '-' + arch);
if (LINUX.equalsIgnoreCase(os)) {
// Fedora SSL lib so naming (libssl.so.10 vs libssl.so.1.0.0)..
libNames.add("netty-tcnative-" + os + '-' + arch + "-fedora");
}
// finally the default library.
libNames.add("netty-tcnative");
NativeLibraryLoader.loadFirstAvailable(SSL.class.getClassLoader(),
libNames.toArray(new String[libNames.size()]));
}
当它单独工作时(例如从 JUnit 测试),它会在 netty-tcnative-boringssl-static jar 中找到 SSL 类,并从这些 jar 依赖项中的 WEB-INF/native 中获取 native 库。 但是当它在 tomcat 下工作时,它从 tomcat 库中获取 SSL 类并且找不到 native 库。
试过 tomcat 8 和 9
最佳答案
这将很快得到修复并成为 4.1.9.Final 的一部分:
关于java - io.netty.handler.ssl.OpenSsl 使用 tomcat 类而不是自身,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41909764/