netty / netty-tcnative

A fork of Apache Tomcat Native, based on finagle-native

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Suppressed: java.lang.UnsatisfiedLinkError: could not load a native library: netty_tcnative_windows_x86_64

gm100861 opened this issue · comments

i want to youse openssl instead jdk ssl, because jdk ssl to slow. but when i add netty-tcnative-boringssl-static to my gradle , start the project and got error.


Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-07-27 21:41:01.857 ERROR 36124 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:163)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:302)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290)
	at com.nenglian.gateway.GatewayApplication.main(GatewayApplication.java:15)
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:142)
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:104)
	at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:473)
	at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:206)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:182)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:160)
	... 8 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sslHandlerServer': Unsatisfied dependency expressed through field 'sslContextFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sslContextFactory': Invocation of init method failed; nested exception is java.lang.UnsatisfiedLinkError: failed to load the required native library
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:659)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213)
	at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:212)
	at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:175)
	at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAdaptableBeans(ServletContextInitializerBeans.java:157)
	at org.springframework.boot.web.servlet.ServletContextInitializerBeans.<init>(ServletContextInitializerBeans.java:87)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplicationContext.java:260)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:234)
	at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:53)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5219)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386)
	at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
	at java.util.concurrent.FutureTask.run(FutureTask.java)
	at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
	at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919)
	at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:835)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386)
	at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
	at java.util.concurrent.FutureTask.run(FutureTask.java)
	at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
	at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919)
	at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:263)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.StandardService.startInternal(StandardService.java:432)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:927)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.startup.Tomcat.start(Tomcat.java:486)
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:123)
	... 13 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sslContextFactory': Invocation of init method failed; nested exception is java.lang.UnsatisfiedLinkError: failed to load the required native library
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:160)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:440)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1389)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1309)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:656)
	... 56 common frames omitted
Caused by: java.lang.UnsatisfiedLinkError: failed to load the required native library
	at io.netty.handler.ssl.OpenSsl.ensureAvailability(OpenSsl.java:596)
	at io.netty.handler.ssl.ReferenceCountedOpenSslContext.<init>(ReferenceCountedOpenSslContext.java:214)
	at io.netty.handler.ssl.OpenSslContext.<init>(OpenSslContext.java:45)
	at io.netty.handler.ssl.OpenSslServerContext.<init>(OpenSslServerContext.java:349)
	at io.netty.handler.ssl.OpenSslServerContext.<init>(OpenSslServerContext.java:336)
	at io.netty.handler.ssl.SslContext.newServerContextInternal(SslContext.java:473)
	at io.netty.handler.ssl.SslContextBuilder.build(SslContextBuilder.java:606)
	at com.nenglian.gateway.http.enterprise.SslContextFactory.init(SslContextFactory.java:65)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:389)
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:333)
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:157)
	... 68 common frames omitted
Caused by: java.lang.IllegalArgumentException: Failed to load any of the given libraries: [netty_tcnative_windows_x86_64, netty_tcnative_x86_64, netty_tcnative]
	at io.netty.util.internal.NativeLibraryLoader.loadFirstAvailable(NativeLibraryLoader.java:107)
	at io.netty.handler.ssl.OpenSsl.loadTcNative(OpenSsl.java:705)
	at io.netty.handler.ssl.OpenSsl.<clinit>(OpenSsl.java:146)
	... 82 common frames omitted
	Suppressed: java.lang.UnsatisfiedLinkError: could not load a native library: netty_tcnative_windows_x86_64
		at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:217)
		at io.netty.util.internal.NativeLibraryLoader.loadFirstAvailable(NativeLibraryLoader.java:98)
		... 84 common frames omitted
	Caused by: java.io.FileNotFoundException: META-INF/native/netty_tcnative_windows_x86_64.dll
		at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:164)
		... 85 common frames omitted
		Suppressed: java.lang.UnsatisfiedLinkError: no netty_tcnative_windows_x86_64 in java.library.path
			at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
			at java.lang.Runtime.loadLibrary0(Runtime.java:870)
			at java.lang.System.loadLibrary(System.java:1122)
			at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
			at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:319)
			at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:139)
			... 85 common frames omitted
			Suppressed: java.lang.UnsatisfiedLinkError: no netty_tcnative_windows_x86_64 in java.library.path
				at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
				at java.lang.Runtime.loadLibrary0(Runtime.java:870)
				at java.lang.System.loadLibrary(System.java:1122)
				at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
				at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
				at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
				at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
				at java.lang.reflect.Method.invoke(Method.java:498)
				at io.netty.util.internal.NativeLibraryLoader$1.run(NativeLibraryLoader.java:353)
				at java.security.AccessController.doPrivileged(Native Method)
				at io.netty.util.internal.NativeLibraryLoader.loadLibraryByHelper(NativeLibraryLoader.java:345)
				at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:311)
				... 86 common frames omitted
	Suppressed: java.lang.UnsatisfiedLinkError: could not load a native library: netty_tcnative_x86_64
		at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:217)
		at io.netty.util.internal.NativeLibraryLoader.loadFirstAvailable(NativeLibraryLoader.java:98)
		... 84 common frames omitted
	Caused by: java.io.FileNotFoundException: META-INF/native/netty_tcnative_x86_64.dll
		at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:164)
		... 85 common frames omitted
		Suppressed: java.lang.UnsatisfiedLinkError: no netty_tcnative_x86_64 in java.library.path
			at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
			at java.lang.Runtime.loadLibrary0(Runtime.java:870)
			at java.lang.System.loadLibrary(System.java:1122)
			at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
			at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:319)
			at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:139)
			... 85 common frames omitted
			Suppressed: java.lang.UnsatisfiedLinkError: no netty_tcnative_x86_64 in java.library.path
				at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
				at java.lang.Runtime.loadLibrary0(Runtime.java:870)
				at java.lang.System.loadLibrary(System.java:1122)
				at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
				at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
				at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
				at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
				at java.lang.reflect.Method.invoke(Method.java:498)
				at io.netty.util.internal.NativeLibraryLoader$1.run(NativeLibraryLoader.java:353)
				at java.security.AccessController.doPrivileged(Native Method)
				at io.netty.util.internal.NativeLibraryLoader.loadLibraryByHelper(NativeLibraryLoader.java:345)
				at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:311)
				... 86 common frames omitted
	Suppressed: java.lang.UnsatisfiedLinkError: could not load a native library: netty_tcnative
		at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:217)
		at io.netty.util.internal.NativeLibraryLoader.loadFirstAvailable(NativeLibraryLoader.java:98)
		... 84 common frames omitted
	Caused by: java.io.FileNotFoundException: META-INF/native/netty_tcnative.dll
		at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:164)
		... 85 common frames omitted
		Suppressed: java.lang.UnsatisfiedLinkError: no netty_tcnative in java.library.path
			at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
			at java.lang.Runtime.loadLibrary0(Runtime.java:870)
			at java.lang.System.loadLibrary(System.java:1122)
			at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
			at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:319)
			at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:139)
			... 85 common frames omitted
			Suppressed: java.lang.UnsatisfiedLinkError: no netty_tcnative in java.library.path
				at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
				at java.lang.Runtime.loadLibrary0(Runtime.java:870)
				at java.lang.System.loadLibrary(System.java:1122)
				at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
				at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
				at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
				at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
				at java.lang.reflect.Method.invoke(Method.java:498)
				at io.netty.util.internal.NativeLibraryLoader$1.run(NativeLibraryLoader.java:353)
				at java.security.AccessController.doPrivileged(Native Method)
				at io.netty.util.internal.NativeLibraryLoader.loadLibraryByHelper(NativeLibraryLoader.java:345)
				at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:311)
				... 86 common frames omitted

and my SslContext is

package com.nenglian.gateway.http.enterprise;

import com.nenglian.gateway.config.ProxyConfig;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.SslHandler;
import io.netty.handler.ssl.SslProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.net.ssl.*;
import java.io.FileInputStream;
import java.security.KeyStore;
/**
 * 初始化sslcontext类
 *
 */
@Component
public class SslContextFactory {

    private static final Logger LOGGER = LoggerFactory.getLogger(SslContextFactory.class);

    private final ProxyConfig proxyConfig;

    private static final String ALGORITHM = "SunX509";
    private static final String KEY_STORE_TYPE = "JKS";
    private static final String PROTOCOL = "SSLv3";

//    private SSLContext sslContext = null;

    private SslContext sslContext;

    public SslContextFactory(ProxyConfig proxyConfig) {
        this.proxyConfig = proxyConfig;
    }

    public SslContext getSslContext() {
        return sslContext;
    }

    /**
     * 初始化SSLContext
     */
    @PostConstruct
    private void init() {
        synchronized (this) {
            if (sslContext != null) {
                LOGGER.info("ssl context is already init");
            }
            try (FileInputStream inputStream = new FileInputStream(proxyConfig.getJksPath()); FileInputStream trustManagerInputStream = new FileInputStream(proxyConfig.getJksPath())) {
                //sslContext = SSLContext.getInstance(PROTOCOL);
                KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(ALGORITHM);
                KeyStore keyStore = KeyStore.getInstance(KEY_STORE_TYPE);
                keyStore.load(inputStream, proxyConfig.getJksPasswd().toCharArray());
                keyManagerFactory.init(keyStore, proxyConfig.getJksPasswd().toCharArray());
                KeyManager[] keyManagers = keyManagerFactory.getKeyManagers();

                TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(ALGORITHM);
                keyStore.load(trustManagerInputStream, proxyConfig.getJksPasswd().toCharArray());
                trustManagerFactory.init(keyStore);
                TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();

                sslContext = SslContextBuilder.forServer(keyManagerFactory).trustManager(trustManagerFactory).sslProvider(SslProvider.OPENSSL).build();
                //sslContext.init(keyManagers, trustManagers, null);
                //sslContext.createSSLEngine().getSupportedCipherSuites();
            } catch (Exception e) {
                LOGGER.error("初始化SSL Context时异常:", e);
            }
        }
    }
}

my netty and openssl version


    implementation group: 'io.netty', name: 'netty-all', version: '4.1.79.Final'
	// https://mvnrepository.com/artifact/kr.motd.maven/os-maven-plugin
	implementation group: 'kr.motd.maven', name: 'os-maven-plugin', version: '1.7.0'
	// https://mvnrepository.com/artifact/io.netty/netty-tcnative-boringssl-static
	implementation group: 'io.netty', name: 'netty-tcnative-boringssl-static', version: '2.0.52.Final

i google it, and got issue-331, but can't find how do resolve it.

#331

netty/netty issue