微服务之--服务管理

服务管理 配置 pom.xml(继承eureka服务后面的配置)



    4.0.0
    
        com.example
        spring-cloud
        2.0-SNAPSHOT
         
    

    com.example
    admin-server
    0.0.1-SNAPSHOT
    admin-server
    Demo project for Spring Boot

    
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
            2.0.1.RELEASE
        

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


    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    


 

配置application.yml

server:
  port: 5000 #访问端口
spring:
  application:
    name: admin-server
  security:
    user:
      name: 'admin'
      password: '123456'
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/
    registry-fetch-interval-seconds: 5
  instance:
    lease-renewal-interval-in-seconds: 10
    health-check-url-path: /actuator/health
    metadata-map:
      user.name: ${spring.security.user.name}
      user.password: ${spring.security.user.password}
    prefer-ip-address: true
management:
  endpoint:
    health:
      show-details: always
  endpoints:
    web:
      exposure:
        include: "*"

 

启动类

package com.example.adminserver;

import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * 网页登录 查询启动的服务
 */
@SpringBootApplication
@EnableAdminServer
public class AdminServerApplication {

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

}

 

SecuritySecureConfig类:;

package com.example.adminserver;

import de.codecentric.boot.admin.server.config.AdminServerProperties;
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;


@Configuration
public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {

    private final String adminContextPath;

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

    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();
    }


}

 

启动服务后  浏览器输入: localhost:5000 可查看所有你启动的服务

微服务之--服务管理_第1张图片

你可能感兴趣的:(hibernate)