1

i use intellij and java 1.8 for running my springboot

i have tried to create main jar like this on my code :

@SpringBootApplication
@RestController
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    private DemoMetricReaderWriter demoMetricReaderWriter = new DemoMetricReaderWriter();

    @Bean
    @ExportMetricReader
    @ExportMetricWriter
    DemoMetricReaderWriter getReader() {
        return demoMetricReaderWriter;
    }

    @RequestMapping("/")
    String home() throws Exception {
        long start = System.currentTimeMillis();

        // insert up to 2 second delay for a wider range of response times
        Thread.sleep((long) (Math.random() * 2000));

        // let that delay become the gauge.bar metric value
        long barValue = System.currentTimeMillis() - start;

        demoMetricReaderWriter.updateMetrics(barValue);
        return "Hello World!";
    }
}

but when i build and run my jar i got error like this. and i have try to fix but i don't know what is exactly problem for this

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.example.demo.DemoApplication]; nested exception is java.lang.IllegalArgumentException: Could not find class [org.springframework.boot.autoconfigure.condition.ConditionalOnJava$JavaVersion]

this is my gradle.build for create this apps.

    plugins {
    id 'org.springframework.boot' version '2.5.1'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}
jar {
    manifest {
        attributes 'Main-Class': 'com.example.demo.DemoApplication'
    }
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

configurations {
    all {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
        exclude group: 'ch.qos.logback', module: 'logback-classic'
    }
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
    google()
}

dependencies {
    // spring boot
    implementation ('org.springframework.boot:spring-boot-starter-web') {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
    }
    implementation 'org.springframework.boot:spring-boot-starter-undertow'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'

    // health check
    implementation 'org.springframework.boot:spring-boot-actuator:1.5.14.RELEASE'

    // logging
    implementation 'org.springframework.boot:spring-boot-starter-log4j2'
    implementation 'com.lmax:disruptor:3.4.2'

    // database
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-data-mongodb:2.5.5'
    runtimeOnly 'com.oracle.ojdbc:ojdbc8'
    runtimeOnly 'org.postgresql:postgresql'


    //datadog
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'org.apache.httpcomponents:httpclient:4.5.3'
    implementation 'org.springframework.boot:spring-boot-actuator:1.5.14.RELEASE'


    // lombok
    compileOnly 'org.projectlombok:lombok'



    // testing
    testImplementation 'org.mockito:mockito-core:3.9.0'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.security:spring-security-test'
    testImplementation 'io.projectreactor:reactor-test'
    annotationProcessor 'org.projectlombok:lombok'
}

test {
    useJUnitPlatform()
}

my question what is wrong on my code ? for run this code i use gradle i have tried use example from internet but still getting error.... how to fix this problem ?

javadev
  • 688
  • 2
  • 6
  • 17
aaaaaajib
  • 49
  • 1
  • 6

1 Answers1

0

There is a dependency conflict with the module containing ConditionalOnJava. ConditionalOnJava is part of module spring-boot-autoconfigure. Let's see which version is selected by Gradle. To do so, we issue the following command:

gradlew -q dependencyInsight --dependency spring-boot-autoconfigure --configuration runtimeClasspath

The relevant output for us is

org.springframework.boot:spring-boot-autoconfigure:1.5.14.RELEASE -> 2.5.1
\--- org.springframework.boot:spring-boot-actuator:1.5.14.RELEASE
     \--- runtimeClasspath

This tells us that spring-boot-actuator:1.5.14.RELEASE depends on spring-boot-autoconfigure:1.5.14.RELEASE. ConditionalOnJava indeed contains a subclass JavaVersion in version 1.15.14.RELEASE (ConditionalOnJava$JavaVersion part of the error message). However, Gradle also tells us that spring-boot-actuator is upgraded to 2.5.1 and that version doesn't contain the subclass JavaVersion anymore.

I'm afraid you need to upgrade Spring Boot Actuator to the version related to the Spring Boot version you're running:

implementation 'org.springframework.boot:spring-boot-starter-actuator'

Sending actuator metrics to Datadog is available through Micrometer with starter io.micrometer:micrometer-registry-datadog, see Actuator Metrics documentation for details.

thokuest
  • 5,800
  • 24
  • 36
  • yup... i need to use the latest actuator.. but if i use latest actuator there is no package ExportMetricReader ExportMetricWriter this annotation... and other my question is if i want to send http status log to datadog how to that ? – aaaaaajib Oct 27 '21 at 02:40
  • Datadog integration is now available through [Micrometer](https://micrometer.io/) with starter `io.micrometer:micrometer-registry-datadog`, see [Actuator Metrics](https://docs.spring.io/spring-boot/docs/2.5.6/reference/htmlsingle/#actuator.metrics) for details. – thokuest Oct 27 '21 at 07:14