简体   繁体   中英

java.lang.NoSuchFieldError: INSTANCE only when running on Tomcat

I'm using Apache's httpcomponents to connect to a webservice. When I run my tests, initializing the client goes without problem. When I want to do an actual integration test however, I get the aforementioned exception with following stack trace:

java.lang.NoSuchFieldError: INSTANCE
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:151)
    at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:969)
    at eu.sonetas.fuga.rs.foo.FooRs.<init>(IbanityRs.java:64)
    at eu.sonetas.fuga.rs.foo.FooRs_EInvoicing.<init>(fooRs_EInvoicing.java:45)

I'm using httpclient 4.5.13, httpcore 4.4.14 and httpmime 4.5.13 (all latest versions) and tomcat 9.0.6.

I don't use any build tools, and I am pretty sure there's no other versions of the above jars on my class path.

This is the calling code where things go wrong:

public FooRs() throws FooException {
        try {
            SSLContext sslContext = SSLContexts.custom()
                .loadKeyMaterial(readStore(), KEYPASS.toCharArray())
                .build();
                this.httpClient = HttpClients.custom().setSSLContext(sslContext).build();
                //
        } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException | UnrecoverableKeyException e) {
            throw new FooException("Could not initialize FooRs:" + e.getMessage());
        }
        
    }

这个问题是由我的类路径上旧版本的 httpclient-cache 引起的

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM