SpringBoot2.x搭建SpringBootAdmin2.x
1 说明
- 全部配置基于
1.8.0_111 - 当前SpringBoot使用
2.0.5 - SpringBootAdmin基于Eureka进行Client发现,Eureka搭建参见SpringBoot2.x搭建Eureka
- SpringBootAdmin项目文档参见SpringBootAdmin参考文档
2 创建项目
在SpringBoot项目生成器中,输入Group和Artifact,如下配置:

3 编辑pom.xml文件
pom.xml中新添加如下内容:
<properties>
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
4 修改application.properties为application.yml文件
编辑application.properties为application.yml文件,添加以下内容:
server:
port: 8099
spring:
application:
name: SpringBootAdmin
security:
user:
name: anxminise
password: 123456
boot:
admin:
ui:
title: 忧臣解读
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
eureka:
instance:
metadata-map:
user.name: anxminise
user.password: 123456
easeRenewalIntervalInSeconds: 10
health-check-url-path: /actuator/health
ip-address: 127.0.0.1
prefer-ip-address: true
instance-id: ${eureka.instance.ip-address}:${server.port}
client:
registryFetchIntervalSeconds: 5
serviceUrl:
defaultZone: http://anxminise:123456@127.0.0.1:8888/eureka/
配置参数解释:
| 参数 | 说明 |
|---|---|
| security.user.name | SpringBootAdmin登录时的用户名 |
| security.user.password | SpringBootAdmin登录时的密码 |
| eureka.instance.metadata-map.user.name | SpringBootAdmin本身作为一个Eureka客户端被发现,这里由于SpringBootAdmin需要进行登录,因此,此处配置SpringBootAdmin登录时使用的用户名 |
| eureka.instance.metadata-map.user.password | 同上,配置SpringBootAdmin登录使用的密码 |
5 编辑SpbadminApplication.java文件
最后编辑SpbadminApplication.java文件,修改为:
@EnableDiscoveryClient
@EnableAdminServer
@SpringBootApplication
public class SpbadminApplication {
public static void main(String[] args) {
SpringApplication.run(SpbadminApplication.class, args);
}
@Configuration
public static class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
private final String adminContextPath;
public SecuritySecureConfig(AdminServerProperties adminServerProperties) {
this.adminContextPath = adminServerProperties.getContextPath();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
successHandler.setTargetUrlParameter("redirectTo");
successHandler.setDefaultTargetUrl(adminContextPath + "/");
http.authorizeRequests()
.antMatchers(adminContextPath + "/assets/**").permitAll()
.antMatchers(adminContextPath + "/login").permitAll()
.anyRequest().authenticated()
.and()
.formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and()
.logout().logoutUrl(adminContextPath + "/logout").and()
.httpBasic().and()
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.ignoringAntMatchers(
adminContextPath + "/instances",
adminContextPath + "/actuator/**"
);
}
}
}
6 编译并启动运行
注:本次SpringBootAdmin是基于Eureka搭建的,需要先启动Eureka
./mvnw clean package -DskipTests #编辑应用
java -jar target/spbadmin-0.0.1-SNAPSHOT.jar #启动应用,注:jar包的名称应换成自己的



7 Eureka客户端监控
SpringBootAdmin的作用是:监控Eureka中的微服务,这里的微服务,我们使用SpringBoot2.x进行开发,对于SpringBoot2.x的SpringBoot项目,只需在application.yml中新加入以下内容:
logging:
path: logs/log
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
参数解释说明
| 参数 | 说明 |
|---|---|
| logging.path | 配置日志的存放路径,此处用于SpringBootAdmin的日志监控 |
| management.* | 配置SpringBoot的全部监控点,此处注意:当前配置未对endpoint进行访问保护,勿对外网开放,后续我们加入对其的访问保护 |
SpringBoot2.x搭建SpringBootAdmin2.x的更多相关文章
- SpringBoot2.x搭建Eureka
1 说明 全部配置基于1.8.0_111 当前SpringBoot使用2.0.5 2 创建项目 在SpringBoot项目生成器中,输入Group和Artifact,如下配置: 3 pom.xml配置 ...
- Spring Boot 2.X 如何添加拦截器?
最近使用SpringBoot2.X搭建了一个项目,大部分接口都需要做登录校验,所以打算使用注解+拦截器来实现,在此记录下实现过程. 一.实现原理 1. 自定义一个注解@NeedLogin,如果接口需要 ...
- WebFlux03 SpringBoot WebFlux实现CRUD
1 准备 基于SpringBoot2.0搭建WebFlux项目,详情请参见三少另外一篇博文 2 工程结构 <?xml version="1.0" encoding=" ...
- 使用JWT来实现单点登录功能
出处: https://www.cnblogs.com/zexin/p/10389541.html 我们平时自己开发项目,分布式的结构时,访问量不大,但是又不想搭建redis服务器,这时我觉得jwt不 ...
- 如何使用JWT来实现单点登录功能
我们平时自己开发项目,分布式的结构时,访问量不大,但是又不想搭建redis服务器,这时我觉得jwt不错. 个人理解,jwt就是类似于一把锁和钥匙,客户来租房(登录),我们需要给他进来(第一次登录)登记 ...
- SpringBoot2.0基础案例(01):环境搭建和RestFul风格接口
一.SpringBoot 框架的特点 1.SpringBoot2.0 特点 1)SpringBoot继承了Spring优秀的基因,上手难度小 2)简化配置,提供各种默认配置来简化项目配置 3)内嵌式容 ...
- SpringBoot2整合activiti6环境搭建
SpringBoot2整合activiti6环境搭建 依赖 <dependencies> <dependency> <groupId>org.springframe ...
- SpringBoot2 整合Nacos组件,环境搭建和入门案例详解
本文源码:GitHub·点这里 || GitEE·点这里 一.Nacos基础简介 1.概念简介 Nacos 是构建以"服务"为中心的现代应用架构,如微服务范式.云原生范式等服务基础 ...
- SpringBoot2.x【一】从零开始环境搭建
SpringBoot2.x[一]从零开始环境搭建 对于之前的Spring框架的使用,各种配置文件XML.properties一旦出错之后错误难寻,这也是为什么SpringBoot被推上主流的原因,Sp ...
随机推荐
- Linux操作中应该注意的问题
1.覆盖问题 (1)cp覆盖 (2)scp覆盖 (3)重定向 “>” 覆盖 (4)tar覆盖 2.磁盘问题 (1)GPT格式的分区会覆盖磁盘上原有的分区 (2)在/etc/fstab中写入完成后 ...
- 异常CLRDBG_NOTIFICATION_EXCEPTION_CODE( 0x04242420)
简介 CLRDBG_NOTIFICATION_EXCEPTION_CODE,值为0x0x04242420.此异常在.CLR 4.0的启动路径期间触发,是CLR4.0版本初始化调试服务时向调试器发送消息 ...
- CF598: div3解题报告
CF598:div3解题报告 A: Payment Without Change 思路: 按题意模拟即可. 代码: #include<bits/stdc++.h> using namesp ...
- MYSQL:基于哈希的索引和基于树的索引有什么区别?
B+树是一个平衡的多叉树.B+树从根节点到叶子节点的搜索效率基本相当,不会出现大幅波动. 哈希索引采用一定的哈希算法,把键值换成新的哈希值,检索时不需要类似B+树那样从根节点逐级查找,只需一次哈希算法 ...
- Http状态码梳理汇总
常见的状态代码为:200 - 服务器成功返回网页404 - 请求的网页不存在503 - 服务器暂时不可用 1xx(临时响应) 用于表示临时响应并需要请求者执行操作才能继续的状态代码.代码 说明 100 ...
- GitHub 干货 | 各大数据竞赛 Top 解决方案开源汇总
AI 科技评论编者按:现在,越来越多的企业.高校以及学术组织机构通过举办各种类型的数据竞赛来「物色」数据科学领域的优秀人才,并借此激励他们为某一数据领域或应用场景找到具有突破性意义的方案,也为之后的数 ...
- UDF——文件编码造成UDF编译失败
有时候我们觉得我们的代码写得很正确的,但是在Fluent当中编译的时候一直编译不通过,提示我们错误,我们根据Fluent当中的错误提示去找到源代码中对应的行,却发现没有错误提示当中的问题,出现这个问题 ...
- Git-push和pull分支
查看分支信息:git branch -r 查看所有分支信息:git branch -a 本地推送分支:git push origin branch-name 推送分支前最好先pull分支:git pu ...
- Golang(四)正则表达式使用
0. 前言 最近用到了 regexp 包,下面整理下正则表达式相关用法 参考 基础知识 - Golang 中的正则表达式 和 Golang regexp包中的函数和方法 做了汇总 1. 正则表达式 1 ...
- CnblogAndroid使用反馈 & PureMan6留言板
我们的话: 您可以在这篇博客下评论您使用CnblogAndroid时遇到的问题和您的意见与建议: 或是留言给PureMan6团队,我们会定期查看并进行回复. 同时,关于app的问题,您也可以在Cnbl ...