springeureka集成springboot admin

z感谢:https://cloud.tencent.com/developer/article/1427320

可以把admin集成在zuul同一个服务上,前提zuul已经和eureka集成,那么admin自动就集成了eureka

admin和zuul的配置pom和yml,以及zuul的启动类加上@EnableAdminServer

spring:
  application: 
    name: zuul-api 
  profiles:
    active: #spring.profiles.active#
  security:##必要的admin配置
    user:
      name: "admin"
      password: "admin" 

eureka:
  client:
    service-url:
      defaultZone: http://192.168.1.173:18760/eureka/
  instance:
    hostname: localhost
    status-page-url: http://${spring.cloud.client.ipaddress}:${server.port}
    instance-id: zuul-apigateway(${spring.cloud.client.ipaddress}:${server.port})
    preferIpAddress: true
    leaseRenewalIntervalInSeconds: 10
    leaseExpirationDurationInSeconds: 30
    metadata-map:##必要的admin配置
      user.name: ${spring.security.user.name}
      user.password: ${spring.security.user.password}
<properties>
		<java.version>1.8</java.version>
		<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
		<spring-boot-admin.version>2.1.0</spring-boot-admin.version>
	</properties>


<dependency>
			<groupId>de.codecentric</groupId>
			<artifactId>spring-boot-admin-starter-server</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-security</artifactId>
		</dependency><!--这个用来管理admin登录-->



	<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>
			<dependency>
				<groupId>de.codecentric</groupId>
				<artifactId>spring-boot-admin-dependencies</artifactId>
				<version>${spring-boot-admin.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>
package com.jzlife.management.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;

import de.codecentric.boot.admin.server.config.AdminServerProperties;

@Configuration
public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {

	    private final String adminContextPath;

	    public SecuritySecureConfig(AdminServerProperties adminServerProperties) {
	        this.adminContextPath = adminServerProperties.getContextPath();
	    }

	    @Override
	    protected void configure(HttpSecurity http) throws Exception {
	        // @formatter:off
	        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()
	                //启用HTTP-Basic支持。这是Spring Boot Admin Client注册所必需的
	                .httpBasic().and();
	        // @formatter:on
	    }
	}

其他业务服务加入配置

management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: ALWAYS

eureka注册中心加入以下配置就好了

<dependency>
			<groupId>de.codecentric</groupId>
			<artifactId>spring-boot-admin-starter-client</artifactId>
		</dependency>

<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>de.codecentric</groupId>
				<artifactId>spring-boot-admin-dependencies</artifactId>
				<version>2.1.0</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>

		</dependencies>
	</dependencyManagement>

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值