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.
http://localhost:8080
?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?
- 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.
- 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.
- 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.