栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

spring boot admin服务搭建

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

spring boot admin服务搭建

1、springboot admin 服务端 1-1)新建springboot 项目,pom.xml文件引入一下依赖

	
	      de.codecentric
	      spring-boot-admin-starter-server
	      ${spring.admin.version}
	


	 
	    org.springframework.boot
	        spring-boot-starter-security
	        2.5.2
	


	
	  org.springframework.boot
	  spring-boot-starter-mail
	
1-2)资源配置文件引入配置
#代表打开所有的监控点
management:
  endpoints:
    web:
      exposure:
        include: "*"
      # 代表启用单独的url地址来监控 Spring Boot 应用,
      base-path: /
  endpoint:
    health:
      show-details: always

#程序名称
spring:
  main:#配置是否开启权限认证标识 
    allow-circular-references: true
  cloud:
    compatibility-verifier:
      enabled: false

  #配置自定义web页面banner
  boot:
    admin:
      ui:
        title: 服务监控系统
        brand: >服务监控系统
        cache:
          no-cache: true
          no-store: true
  mail: #配置发送邮件邮箱
    host: smtp.163.com
    username: xxxx@163.com
    password: xxxxx
1-3)spring boot服务后台代码 1-3-1 主程序启动配置
@SpringBootApplication
@EnableAdminServer
//过滤掉数据库加载
@EnableAutoConfiguration(exclude ={DataSourceAutoConfiguration.class})
public class MonitorApplication{
    public static void main(String[] args) {
        SpringApplication.run(MonitorApplication.class,args);
    }
}
1-3-2 启用安全检查配置
@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 {
        SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
        successHandler.setTargetUrlParameter("redirectTo");
        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().disable();
    }
}
2、springboot admin 客户端 2-1 pom引入配置如下
  
      de.codecentric
      spring-boot-admin-starter-client
      ${spring.admin.version}
  
2-2 ymal配置文件设置
#客户端访问服务端地址,用户名密码配置
spring:
  boot:
    admin:
      client:
        url: http://localhost:8099
        username: admin
        password: ****
#监控客户端程序的访问路径配置
management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: always
    logfile: #客户端文件输出配置
      external-file:  ./server-log/output.log
2-3 输出日志文件配置


    
       ${APP_Name}
    
    

    
    
    
    
    
    

    
    
        
            ${CONSOLE_LOG_PATTERN}
            utf8
        
    

    
    
        ${LOG_HOME}/output.log
        
            
            ${LOG_HOME}/server-%d{yyyy-MM-dd}.log
            
            30
        
        
            
            %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n
            ${CONSOLE_LOG_PATTERN}
            utf8
        
    

    
    
        
     

    
        
    



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/826531.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号