简体   繁体   中英

Spring Boot application + Jolokia - exception during startup

I'm using Spring Boot 1.5.3.RELEASE and Jolokia 1.3.6 (also happens in later versions).

The Jolokia is integrated by adding a dependency:

 <dependency>
     <groupId>org.jolokia</groupId>
     <artifactId>jolokia-core</artifactId>
 </dependency>

One of our microservices that all share the same architecture fails to start and I see the exception with the following root-cause during the startup:

Caused by: java.io.FileNotFoundException: JAR entry BOOT-INF/lib/jolokia-core-1.3.7.jar!/META-INF/simplifiers-default not found in <MY_JAR_NAME_GOES_HERE>.jar
    at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:142)
    at sun.net.www.protocol.jar.JarURLConnection.getInputStream (JarURLConnection.java:150)
    at java.net.URL.openStream(URL.java:1045)
    at org.jolokia.util.ServiceObjectFactory.readServiceDefinitionFromUrl(ServiceObjectFactory.java:90)

This exception doesn't happen when I start the application from the IDE, only when I start with java -jar <MY_JAR> .

I looked at the line that produces exception inside the code of Jolokia, and it looks like this:

reader = new LineNumberReader(new InputStreamReader(new URL(pUrl).openStream(),"UTF8"));

So I conclude (after debugging) that new URL(pUrl).openStream() fails to find a jar entry as specified in the aforementioned exception stack trace. I also understand that in IDE it doesn't happen because it works with different classloaders (Spring Boot application uses LaunchedURLClassLoader ).

However, I don't see a bug here in the source code: we have a lot of microservices, all are running with the same configurations and it works as expected, in addition, as far as I know this is the documented way for Jolokia integration.

So I suspect some race condition here or something, but I can't really point out exactly what happens here.

Did anyone encounter such a problem? Is there a workaround?

I was getting exactly the same exception. The problem in my case was that the filename had a + (I'm using reckon Gradle plugin to generate the project version). The solution was to rename the file before running it with java -jar .

I'm facing the same problem, with Spring Boot 1.5.22 and default version of jolokia.

I have another app (same version of SpringBoot, jolokia) that did not have the problem... I did not find any differences between the 2 apps...

But I have use that workaround : instruct Spring Boot to extract jolokia jar in order to skip Spring boot nested jar url process for jolokia jar only.

         <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <requiresUnpack>
                    <dependency>
                        <artifactId>jolokia-core</artifactId>
                        <groupId>org.jolokia</groupId>
                    </dependency>
                </requiresUnpack>
            </configuration>
        </plugin>

see https://docs.spring.io/spring-boot/docs/1.5.x/reference/htmlsingle/#howto-extract-specific-libraries-when-an-executable-jar-runs

With this workaround, jolokia is happy, the /jolokia endpoint is available and Spring Boot Admin jmx tab is active.

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