I tried to use spring boot actuator to observe my simple application, expecting to observe an application in my office.
My original endpoint worked, but actuator's endpoints did not work with following commands.
Executed commands:
gradle buildjava -jar build/libs/HelloWorld.jarcurl http://localhost:8080/greet/hello-> "Hello world!" was printed (EXPECTED)curl http://localhost:8080/health-> status 404, error: not found (UNEXPECTED)
It seems that actuator's packages were not included, though I compiled spring-boot-starter-actuator-1.5.6.RELEASE.jar.
Could you tell me what was wrong?
My environment:
- Developing server in my office
- Cent OS 7
- Javac 1.8.0_101
- Spring boot 1.5.6
- Gradle 4.6
Structure of my app:
HelloWorld - build.gradle
- setting.gradle
- lib
- src/main/java - Application.java
- GreetController.java
Here are my codes:
build.gradle
buildscript {
repositories {
maven { url "http://192.168.131.247:8081/nexus/content/repositories/maven2/" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.6.RELEASE")
}
dependencies {
classpath fileTree('./lib') {
include '**/*.jar'
}
}
}
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
// configure project
configurations {
provided
//compile.exclude module: "spring-boot-starter-tomcat"
}
sourceSets {
main.compileClasspath += configurations.provided
test.compileClasspath += configurations.provided
test.runtimeClasspath += configurations.provided
}
repositories {
maven { url "http://192.168.131.247:8081/nexus/content/repositories/maven2/" }
}
dependencies {
compile fileTree(dir: './lib', include: ['*.jar'])
testCompile fileTree(dir: './lib', include: ['*.jar'])
}
springBoot {
executable = true
}
settings.gradle
rootProject.name = 'HelloWorld'
lib directory
classmate-1.3.3.jar
commons-collections4-4.1.jar
commons-compiler-2.7.8.jar
commons-daemon-1.0.15.jar
commons-dbcp2-2.1.1.jar
commons-io-2.5.jar
commons-lang3-3.5.jar
commons-logging-1.2.jar
commons-validator-1.6.jar
diffutils-1.2.1.jar
ehcache-2.10.4.jar
hibernate-validator-5.3.5.Final.jar
httpclient-4.5.3.jar
httpcore-4.4.6.jar
jackson-annotations-2.8.0.jar
jackson-core-2.8.9.jar
jackson-databind-2.8.9.jar
jackson-dataformat-cbor-2.8.6.jar
jackson-dataformat-smile-2.8.6.jar
jackson-dataformat-yaml-2.8.6.jar
james-2.3.2.1.jar
janino-2.7.8.jar
jboss-logging-3.3.1.Final.jar
jcl-over-slf4j-1.7.25.jar
jcommander-1.48.jar
jna-4.4.0.jar
joda-time-2.9.5.jar
jopt-simple-5.0.2.jar
json-20140107.jar
json-smart-2.2.1.jar
junit-4.12.jar
lang-mustache-client-5.5.2.jar
libs.txt
log4j-api-2.7.jar
logback-classic-1.1.11.jar
logback-core-1.1.11.jar
lombok-1.16.18.jar
opencsv-4.1.jar
securesm-1.1.jar
slf4j-api-1.7.25.jar
snakeyaml-1.15.jar
spring-aop-4.3.10.RELEASE.jar
spring-beans-4.3.10.RELEASE.jar
spring-boot-1.5.6.RELEASE.jar
spring-boot-autoconfigure-1.5.6.RELEASE.jar
spring-boot-gradle-plugin-1.5.6.RELEASE.jar
**spring-boot-starter-actuator-1.5.6.RELEASE.jar**
spring-boot-starter-aop-1.5.6.RELEASE.jar
spring-boot-starter-jetty-1.5.6.RELEASE.jar
spring-boot-starter-test-1.5.6.RELEASE.jar
spring-boot-starter-web-1.5.6.RELEASE.jar
spring-context-4.3.10.RELEASE.jar
spring-context-support-4.3.10.RELEASE.jar
spring-core-4.3.10.RELEASE.jar
spring-data-commons-1.13.6.RELEASE.jar
spring-data-keyvalue-1.2.6.RELEASE.jar
spring-expression-4.3.10.RELEASE.jar
spring-oxm-4.3.10.RELEASE.jar
spring-test-4.3.10.RELEASE.jar
spring-tx-4.3.10.RELEASE.jar
spring-web-4.3.10.RELEASE.jar
spring-webmvc-4.3.2.RELEASE.jar
testng-6.10.jar
tomcat-embed-core-8.5.4.jar
tomcat-embed-el-8.5.16-sources.jar
tomcat-embed-el-8.5.16.jar
validation-api-1.1.0.Final.jar
Application.java
package com.example.app;
import java.util.Arrays;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
GreetController.java
package com.example.app;
import java.io.IOException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/greet")
public class GreetController {
@GetMapping("/hello")
public String greet (){
return "Hello world!\n";
}
}
I followed Susan' comment, but it didn't work too.
What I did:
- create src/profile/application.yml
- update build.gradle
application.yml
endpoints:
enabled: true
sensitive: false
health:
enabled: true
sensitive: false
info:
enabled: true
sensitive: false
loggers:
enabled: true
sensitive: false
In build.gradle, I added following lines
......
sourceSets {
main.resources {
srcDirs "src/profile"
}
......
}
......