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 ?