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}

		1.8
		Greenwich.RELEASE
		2.1.0
	



			de.codecentric
			spring-boot-admin-starter-server
		
		
			org.springframework.boot
			spring-boot-starter-security
		



	
		
			
				org.springframework.cloud
				spring-cloud-dependencies
				${spring-cloud.version}
				pom
				import
			
			
				de.codecentric
				spring-boot-admin-dependencies
				${spring-boot-admin.version}
				pom
				import
			
		
	
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注册中心加入以下配置就好了


			de.codecentric
			spring-boot-admin-starter-client
		


		
			
				de.codecentric
				spring-boot-admin-dependencies
				2.1.0
				pom
				import
			

		
	

 

 

你可能感兴趣的:(springboot)