springcloud(Hoxton.M3) 集成spring-boot-admin-server

一、软件版本列表:

1、springcloud 版本 Hoxton.M3

<dependencyManagement>

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-parent</artifactId>

<version>Hoxton.M3</version>

<type>pom</type>

<scope>import</scope>

</dependency>

</dependencies>

</dependencyManagement>

2、spring-boot-admin-server 版本 2.2.1

<dependency>

<groupId>de.codecentric</groupId>

<artifactId>spring-boot-admin-server</artifactId>

<version>2.2.1</version>

</dependency>

3、spring-boot-admin-starter-client 版本2.2.1

<dependency>

<groupId>de.codecentric</groupId>

<artifactId>spring-boot-admin-starter-client</artifactId>

<version>2.2.1</version>

</dependency>

二、spring-boot-admin 服务器端配置

1、创建springboot工程 web-monitor作为服务器端监控程序

需要添加maven依赖

<dependency>

<groupId>de.codecentric</groupId>

<artifactId>spring-boot-admin-server</artifactId>

<version>2.2.1</version>

</dependency>

<dependency>

<groupId>de.codecentric</groupId>

<artifactId>spring-boot-admin-server-ui</artifactId>

<version>2.2.1</version>

</dependency>

2、创建boot启动类并添加注解(@EnableAdminServer)设置端口为8003

@SpringBootApplication

@ComponentScan(value ="com.ttsx")

@EnableAdminServer

public class WebMonitorApplication {

public static void main(String[] args) {SpringApplication.run(WebMonitorApplication.class, args);}

}

这里只给出springbootadmin相关代码,关于eureka等相关配置这里不做描述。 



二、spring-boot-admin客户端程序

1、创建boot程序并添加以下依赖。

<dependency>

<groupId>de.codecentric</groupId>

<artifactId>spring-boot-admin-starter-client</artifactId>

<version>2.2.1</version>

</dependency>

2、修改application.yml配置文件

spring:

    boot:

        admin:

            client:

                #这里要指定到web-monitor服务器的IP和端口上

                url:"http://localhost:8003"

management:

        endpoints:

            web:

                exposure:

                    include:"*"

三、启动服务:访问http://localhost:8003 可以看到下面的页面

四、出于安全考虑可以在客户端引入

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-security</artifactId>

</dependency>

然后创建下面的类来安全验证

@Configuration

public class SecurityPermitAllConfigextends WebSecurityConfigurerAdapter {

@Override

    protected void configure(HttpSecurity http)throws Exception {

    http.authorizeRequests().anyRequest().permitAll()

.and().csrf().disable();

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。