0
votes

So I am creating a new spring boot project and wanted to play around with spring-boot-starter-actuator. However I am facing issues when starting the application.

Pom Snippet:

      <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <!--<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

<spring-boot.version>2.2.0.RELEASE</spring-boot.version>

spring-boots on my classpath: enter image description here

Error while starting the application:

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.springframework.boot.actuate.autoconfigure.metrics.orm.jpa.HibernateMetricsAutoConfiguration.bindEntityManagerFactoryToRegistry(HibernateMetricsAutoConfiguration.java:68)

The following method did not exist:

    io.micrometer.core.instrument.binder.jpa.HibernateMetrics.<init>(Lorg/hibernate/SessionFactory;Ljava/lang/String;Ljava/lang/Iterable;)V

The method's class, io.micrometer.core.instrument.binder.jpa.HibernateMetrics, is available from the following locations:

    jar:file:/C:/Users/rahul/.m2/repository/io/micrometer/micrometer-core/1.0.2/micrometer-core-1.0.2.jar!/io/micrometer/core/instrument/binder/jpa/HibernateMetrics.class

It was loaded from the following location:

    file:/C:/Users/rahul/.m2/repository/io/micrometer/micrometer-core/1.0.2/micrometer-core-1.0.2.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of io.micrometer.core.instrument.binder.jpa.HibernateMetrics

At this point the exception happens: enter image description here

However there is only one constructor of HibernateMetrics which looks like this:

public HibernateMetrics(EntityManagerFactory entityManagerFactory, String entityManagerFactoryName, Iterable<Tag> tags) {
        this.tags = Tags.concat(tags, "entityManagerFactory", entityManagerFactoryName);
        this.stats = hasStatisticsEnabled(entityManagerFactory) ? getStatistics(entityManagerFactory) : null;
    }

From the dependency analyzer, one could see that there are not multiple versions of micrometer-core: enter image description here

I also tried with spring-boot-starter-actuator version of 2.2.0.RELEASE but that has the same issue.

I am not sure what am I missing here, any help will be really appreciated.

1
Do you have spring-boot-starter-web on your classpath? And normally you don't need spring-boot-starter. And mixing versions is not a good idea - Dirk Deyne
Hi Dirk, I have updated my question - added a screenshot of all the spring-boot deps. And no, I dont have spring-boot-start-web because it's not a web application. Also as I said, I was consistent with my versions here, the version being 2.2.0.RELEASE. However, since actuator wasn't working, I was playing with different spring-boot versions - RDM
Also, updated the pom deps to remove the 2.2.6-RELEASE version on spring-boot-starter-actuator. So all of them are using the same version now - 2.2.0.RELEASE - RDM
You know spring-boot-starter-actuator creates web-endpoints so... - Dirk Deyne
Looks like you have some other dependency that pulls in an older version of micrometer-core. The version should be 1.3.0 (see mvnrepository.com/artifact/org.springframework.boot/…), but you're reporting 1.0.2. Try listing all dependencies (using mvn dependency:tree) to see which library uses the older version of micrometer-core. - blagerweij

1 Answers

0
votes

Assuming that you'll connect a spring-boot-actuator application to a JMX console. ( "because it's not a web application")

I've used Spring Initializr based on your pom dependencies and a CommandLineRunner example. Github example: https://github.com/thiagochagas/actuator-example

Adjusts: I've removed the "spring-boot-starter" dependency :

<dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter</artifactId>
     <exclusions>
         <exclusion>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-logging</artifactId>
         </exclusion>
     </exclusions>
</dependency>

I've used a Thread.sleep(30000L) in the DemoApplication class to simplify the example.

Install and Run the Application:

./mvnw clean install
java -jar target/demo-0.0.1-SNAPSHOT.jar

Open the jconsole:

$JAVA_HOME/bin/jconsole

While your application is running it should be on the jconsole.

Select your "demo-0.0.1-SNAPSHOT.jar" to analyze: enter image description here

If this message is shown, select the option "Insecure Connection": enter image description here

Analysis of the running application: enter image description here