41

I developed a Spring boot application and the functionality of the application is working fine. However, at the time of startup, I see the below exception multiple times.

When I ran the same application a couple of weeks back I did not see any such exception. The code base has not changed after that. I am wondering if it has to do something with the environment.

The reason for my post is I would like to understand more about the cause of the exception and how to fix it. I could not find much help when I googled. This here did not work.

The Spring batch process extracts data from Oracle DB and writes it into a JSON file after some processing. I have posted the pom.xml.

javax.management.InstanceNotFoundException: org.springframework.boot:type=Admin,name=SpringApplication
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1095) ~[na:1.8.0_161]
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getClassLoaderFor(DefaultMBeanServerInterceptor.java:1444) ~[na:1.8.0_161]
    at com.sun.jmx.mbeanserver.JmxMBeanServer.getClassLoaderFor(JmxMBeanServer.java:1324) ~[na:1.8.0_161]
    at javax.management.remote.rmi.RMIConnectionImpl$6.run(RMIConnectionImpl.java:1365) ~[na:1.8.0_161]
    at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_161]
    at javax.management.remote.rmi.RMIConnectionImpl.getClassLoaderFor(RMIConnectionImpl.java:1362) ~[na:1.8.0_161]
    at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:813) ~[na:1.8.0_161]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:361) ~[na:1.8.0_161]
    at sun.rmi.transport.Transport$1.run(Transport.java:200) [na:1.8.0_161]
    at sun.rmi.transport.Transport$1.run(Transport.java:197) [na:1.8.0_161]
    at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_161]
    at sun.rmi.transport.Transport.serviceCall(Transport.java:196) [na:1.8.0_161]
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568) [na:1.8.0_161]
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) [na:1.8.0_161]
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) [na:1.8.0_161]
    at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_161]
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) [na:1.8.0_161]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_161]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_161]
    at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_161]

POM.xml

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.mySample</groupId>
<artifactId>db-extraction</artifactId>
<version>1.0.0</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.10.RELEASE</version>
</parent>

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-batch</artifactId>
    </dependency>
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc7</artifactId>
        <version>12.1.0.1</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/commons-dbutils/commons-dbutils -->
    <dependency>
        <groupId>commons-dbutils</groupId>
        <artifactId>commons-dbutils</artifactId>
        <version>1.6</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/commons-dbutils/commons-dbutils -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-collections4</artifactId>
        <version>4.1</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
    </dependency>

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency>
</dependencies>


<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-eclipse-plugin</artifactId>
            <configuration>
                <downloadSources>true</downloadSources>
                <downloadJavadocs>true</downloadJavadocs>
            </configuration>
        </plugin>
    </plugins>
</build>

8 Answers 8

76

I had the same issue with IDEA IntelliJ. The problem was IntelliJ's default server configurations. You just need to remove the 'Enable launch optimization' and 'Enable JMX agent' checkboxes, then it works!

Steps:

  • Edit Configurations
  • choose your project
  • remove the 'Enable launch optimization' and 'Enable JMX agent' checkboxes
4
  • 14
    I only needed to untick "Enable JMX agent".
    – ben3000
    Sep 14, 2018 at 1:28
  • Thank you, this worked in Intellij Idea v2019.1.3 with springboot
    – Mark Glass
    Jun 30, 2019 at 18:42
  • The "Edit Configurations" option is inside the Run menu, for those that like me had to search for it. Apr 10, 2021 at 13:20
  • In IntelliJ 2023, choose "Modify options" -> Disable JMX endpoints Feb 1 at 8:12
34

Are you launching this from Eclipse? If so, I found a way to overcome this issue from my Eclipse oxygen: Go to the launch configuration either from the STS plugin Spring Boot dashboard or from Run Configurations from the Run menu. Then untick Enable JMX checkbox and run it. Hope it helps

1
  • 4
    Same problem in Idea
    – agilob
    Aug 24, 2018 at 7:53
14

Seems to answer your question "The reason for my post is I would like to understand more about the cause of the exception and how to fix it. I could not find much help when I googled."

The issue is that JMX/Lifecycle starts immediately, but Spring Boot takes much longer as there are a number of things to be resolved such as application-properties, beans, auto-wiring, etc... So during the time that JMX has started, but Spring Boot has not started, JMX is searching for your SpringApplication (that has not started), so these errors/exceptions get thrown. Once Spring Boot is up, JMX is happy and the errors/exceptions cease.

In my case, I used the solution above to solve the the errors/exceptions from appearing during startup, but I then found that my Boot Dashboard no longer shows the port that my localhost applications were running on....they appear as unknown port. In the Eclipse/STS 3.9.5, I see checkboxes for Enable Life Cycle Management that seems to solve the errors/exceptions from happening during startup, but from this post here it appears you NEED Life Cycle Management and JMX enabled to see your Ports in the Boot Dashboard.

That said, it looks like we simply need to make a choice a.) Have the errors/exception happen during startup and see the ports OR b.) Disable JMX/Lifecycle and keep track of the ports on paper...

hope this helps, adym

1
  • This should be the accepted answer, as it explains what happens and why disabling JMX helps. Please @lincolnadym apply solution to your explanation, so the answer is full. Thank you!
    – jckmlczk
    Jan 14, 2022 at 14:31
7

Unchecking Enable JMX Agent on Edit Configuration window helped me getting rid of the error on IntelliJ. To save settings finding time posting a screenshot:

enter image description here

2

This is normal and nothing to be worried about.

You can see this exception when the log level is in TRACE Or DEGUG. There is always some time lag between RMI TCP server start and spring boot tomcat start up . RMI TCP will start first and it will try to find SpringApplication Insatance which is started latter. till that time RMI TCP server will poll to find this SpringApplication instance .Once it finds SpringApplication instance this error is gone and Auto Configuration of spring boot starts .

1

In IntelliJ IDEA 2021.3.3, you need to do this to get rid of this:

  1. Edit Configurations
  2. Click on Modify options
  3. Tick on Disable JMX agent
  4. Apply
  5. OK

Edit:

If you are using 2023.1.2 or 2023.2 steps 3 will be:

  1. Tick on Disable JMX endpoints
1
  • instead of Disable JMX agent IntelliJ IDEA 2023.1.2 has Disable JMX endpoints?
    – Ali Asjad
    Jun 27, 2023 at 7:22
0

As others have said this is not inherently a bad thing. Assuming you are seeing it because you have set the spring root logging level to DEBUG, you can silence these messages by setting the sun.rmi package logger to ERROR.

I.E. your application.properties should look like

// Set root logger to DEBUG
logging.level.root=DEBUG

// Disable messages from the jmx exporter
logging.level.sun.rmi=ERROR
0

Updated to the Intellij 23.1.2 version screen shots.
In the Run (Edit) Configuration click the "Modify options" and then select the 'Disable launch optimization' and 'Disable JMX endpoints'

enter image description here

enter image description here


then you should see the selections like below

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.