gpt4 book ai didi

java - 如何使用 Spring Boot 执行器?官方步骤无效

转载 作者:行者123 更新时间:2023-12-04 08:01:40 27 4
gpt4 key购买 nike

我尝试使用 spring boot 执行器来观察我的简单应用程序,希望观察我办公室中的应用程序。
我原来的端点可以工作,但是执行器的端点在以下命令中不起作用。
执行的命令:

  • gradle build
  • java -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
  • Spring Boot 1.5.6
  • Gradle 4.6

  • 我的应用程序的结构:
    HelloWorld - build.gradle
    - setting.gradle
    - lib
    - src/main/java - Application.java
    - GreetController.java
    这是我的代码:
    构建.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
    }
    设置.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
    应用程序.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);
    }
    }
    问候 Controller .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

  • 应用程序.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"
    }
    ......
    }
    ......

    最佳答案

    在您的 application.properties 文件中添加以下内容

    endpoints:
    enabled: true
    sensitive: false
    health:
    enabled: true
    sensitive: false
    info:
    enabled: true
    sensitive: false
    loggers:
    enabled: true
    sensitive: false

    关于java - 如何使用 Spring Boot 执行器?官方步骤无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66436727/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com