Spring Boot管理页面 [英] Spring Boot Admin Page

查看:170
本文介绍了Spring Boot管理页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解如何在我的应用程序中使用SBAP,因为它是一个非常方便的开发工具。我正在阅读他们的参考指南,但我我不理解一些事情。
这是我现在申请的pom:

 < project xmlns =http:// maven。 apache.org/POM/4.0.0xmlns:xsi =http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation =http://maven.apache.org/ POM / 4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">
< modelVersion> 4.0.0< / modelVersion>

< packaging> war< / packaging>

< groupId> com.batch.books.test< / groupId>
< artifactId> test< / artifactId>
< version> 0.0.1-SNAPSHOT< / version>

< parent>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-parent< / artifactId>
< version> 1.3.1.RELEASE< / version>
< / parent>

< dependencies>
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-actuator< / artifactId>
< version> 1.3.1.RELEASE< / version>
< / dependency>
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-web< / artifactId>
< version> 1.3.1.RELEASE< / version>
< / dependency>
< dependency>
< groupId> ch.qos.logback< / groupId>
< artifactId> logback-classic< / artifactId>
< version> 1.1.3< / version>
< / dependency>
< dependency>
< groupId> de.codecentric< / groupId>
< artifactId> spring-boot-admin-server< / artifactId>
< version> 1.3.2< / version>
< / dependency>
< dependency>
< groupId> de.codecentric< / groupId>
< artifactId> spring-boot-admin-server-ui< / artifactId>
< version> 1.3.2< / version>
< / dependency>
< dependency>
< groupId> de.codecentric< / groupId>
< artifactId> spring-boot-admin-starter-client< / artifactId>
< version> 1.3.2< / version>
< / dependency>
< / dependencies>

< build>
< finalName> test< / finalName>
< plugins>
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-compiler-plugin< / artifactId>
< version> 3.3< / version>
< / plugin>
< plugin>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-maven-plugin< / artifactId>
< / plugin>
< / plugins>
< / build>

< / project>

这是我的 Application.java

  package app; 

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
@EnableAdminServer
@EnableDiscoveryClient
public class Application {

public static void main(String [] args){
ApplicationContext ctx = SpringApplication.run(Application.class,args);
}

}

我的 application.yml file:

  info:
version:@ pom.version @
stage:test

spring:
application:
name:@ pom.artifactId @
boot:
admin:
url:http:// localhost:8080

剩下的我很困惑。


  1. 我是否将我的应用程序注册为服务器和客户端?

  2. 我如何运行这个应用程序并访问管理页面?他们没有提到要查看管理页面的任何URL。它只是: http:// localhost:8080

  3. 如何设置它以进行开发,但在生产中将其关闭?底部的参考指南说:




我可以将spring-boot-admin包含到我的业务应用程序中?



tl; dr你可以,但你不应该。您可以设置
spring.boot.admin.context-path来改变提供UI和
REST-api的路径,但是根据您可能获得的
应用程序的复杂性麻烦。另一方面,在我看来,
对于监控自己的应用程序没有任何意义。如果您的
申请失败,您的监管工具也会失败。


我认为这意味着你不应该有这个在生产中。因此,如果您无法使用spring boot admin来监控您的应用程序,那么重点是什么?该解决方案是否有2个应用程序,1个是您的业务应用程序,另一个是监视业务应用程序的监视应用程序?

解决方案

< blockquote>


  1. 我是否将我的应用程序注册为服务器和客户端?


在你的例子中,你做到了。管理服务器本身就是一个客户端并不是问题。事实上,spring-boot-admin-sample是以这种方式配置的,因此你可以获得有关管理服务器本身的信息。



  1. 如何运行此应用程序并访问管理页面?他们没有提到要查看管理页面的任何URL。它只是:
    http:// localhost:8080


是的。如果未设置 spring.boot.admin.context-path ,则在root用户上提供admin。因此,如果您在业务应用程序内部运送管理员,则应配置 spring.boot.admin.context-path ,以便在其他地方提供服务。



  1. 如何为开发设置此项但在生产中将其关闭?底部的参考指南说:...


关键在于使用两个单独的应用。这是我们从开发,生产阶段到生产阶段的方式。我们总是将业务与管理服务器分开。如果要在业务应用程序中启用admin-server,请尝试以下方法:
写一个 @Configuration -class只在某个配置文件中有效并将 @EnableAdminServer 移动到此配置。



希望这会有所帮助。


I am trying to understand how to use SBAP in my application because it is a very handy tool for development. I'm reading their reference guide but I'm not understanding a few things. Here is my pom for my application right now:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <packaging>war</packaging>

    <groupId>com.batch.books.test</groupId>
    <artifactId>test</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.1.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
            <version>1.3.1.RELEASE</version>
        </dependency>
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
          <version>1.3.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.1.3</version>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server-ui</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
            <version>1.3.2</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>test</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

And here is my Application.java:

package app;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
@EnableAdminServer
@EnableDiscoveryClient
public class Application {

    public static void main(String[] args) {
        ApplicationContext ctx = SpringApplication.run(Application.class, args);
    }

}

And my application.yml file:

info:
  version: @pom.version@
  stage: test

spring:
  application:
    name: @pom.artifactId@
  boot:
    admin:
      url: http://localhost:8080

The rest I'm very confused about.

  1. So am I registering my application as the server and the client?
  2. How do I run this application and access the admin page? They don't mention any URL to go to to see the admin page. Is it just: http://localhost:8080?
  3. How do I set this up for development but turn it off in production? There reference guide at the bottom says:

Can I include spring-boot-admin into my business application?

tl;dr You can, but you shouldn’t. You can set spring.boot.admin.context-path to alter the path where the UI and REST-api is served, but depending on the complexity of your application you might get in trouble. On the other hand in my opinion it makes no sense for an application to monitor itself. In case your application goes down your monitioring tool also does.

I'm taking that to mean you shouldn't have this in production. So if you can't use spring boot admin to monitor your app in production then what is the point? Is the solution to have 2 applications, 1 which is your business application and the other being your monitoring application that monitors the business app?

解决方案

  1. So am I registering my application as the server and the client?

In your example, you do. It's not problem that the admin server is a client to itself. In fact the spring-boot-admin-sample is configured this way so you get infos about the admin server itself.

  1. How do I run this application and access the admin page? They don't mention any URL to go to to see the admin page. Is it just: http://localhost:8080?

Yes. If you don't set the spring.boot.admin.context-path the admin is served on root. So if you ship the admin along inside your business-app you should configure spring.boot.admin.context-path so that it's served elsewhere.

  1. How do I set this up for development but turn it off in production? There reference guide at the bottom says: ...

The point is just to use two separate applications. This is the way we do it from dev-, over qa- to production-stage. We always separate the business- from the admin-server. If you want to enable the admin-server inside your business-application conditionally try this approach: Write an @Configuration-class wich is only active within a certain profile and move the @EnableAdminServer to this configuration.

Hope this helps.

这篇关于Spring Boot管理页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆