Spring Cloud入门教程-微服务监控Spring Boot Admin
import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@EnableAdminServer
@SpringBootApplication
public class SpringBootAdminServerApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootAdminServerApplication.class, args);
}
@Profile("insecure")
@Configuration
public static class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll() //
.and().csrf().disable(); //
}
}
}
这段代码定义了一个Spring Boot Admin Server的入口类。它使用@EnableAdminServer
注解启用Spring Boot Admin Server的功能,并通过WebSecurityConfigurerAdapter
的子类关闭了安全验证,以便于在开发过程中更快速地进行测试。在生产环境中,应当使用更为严格的安全配置来保护微服务监控端点的安全。
评论已关闭