【发布时间】:2021-05-31 20:08:36
【问题描述】:
我尝试使用 spring boot 执行器来观察我的简单应用程序,期望观察我办公室中的应用程序。
我原来的端点可以工作,但执行器的端点不能使用以下命令。
执行的命令:
gradle buildjava -jar build/libs/HelloWorld.jar-
curl http://localhost:8080/greet/hello-> “世界你好!”曾是 打印(预期) -
curl http://localhost:8080/health-> 状态 404,错误:不是 找到(意外)
虽然我编译了spring-boot-starter-actuator-1.5.6.RELEASE.jar,但似乎没有包含执行器的包。
你能告诉我出了什么问题吗?
我的环境:
- 在我的办公室开发服务器
- Cent OS 7
- Javac 1.8.0_101
- 弹簧靴 1.5.6
- Gradle 4.6
我的应用程序的结构:
HelloWorld - build.gradle
- setting.gradle
- lib
- src/main/java - Application.java
- GreetController.java
这是我的代码:
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目录
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";
}
}
我关注了苏珊的评论,但也没有用。
我做了什么:
- 创建 src/profile/application.yml
- 更新 build.gradle
application.yml
endpoints:
enabled: true
sensitive: false
health:
enabled: true
sensitive: false
info:
enabled: true
sensitive: false
loggers:
enabled: true
sensitive: false
在 build.gradle 中,我添加了以下几行
......
sourceSets {
main.resources {
srcDirs "src/profile"
}
......
}
......
【问题讨论】:
-
谢谢苏珊,但您的建议无效。发生了同样的错误。
-
为什么你有一个包含依赖项的 lib 文件夹而不是让依赖项解决这个问题?基本上击败了拥有这些的目的。您的依赖项很奇怪,因为它们包括 jetty 和 tomcat(它应该是两者之一而不是两者)。您还混合了模块版本(Jackson 和 Spring),这也很麻烦。看起来你试图在配置方面超越 gradle 依赖管理和 spring boot。最后,那些
starter依赖项只包含用于依赖管理的pom.xml/build.gradle。
标签: java spring-boot gradle jar spring-boot-actuator