SpringCloud微服务之Eureka配置

环境

  • springboot版本 2.1.4.RELEASE
  • springcloud版本 Greenwich.SR1
  • jdk1.8
  • maven 3.6.0
  • idea 2017.3

单节点配置

  • Eureka Server

  • pom.xml
    依赖
  • 启动类添加注解
    注解
  • application.yml
    配置
  • 开启身份认证 关闭CSRF防护
@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable(); //关闭csrf
        http.authorizeRequests().anyRequest().authenticated().and().httpBasic(); //开启认证
    }

}
  • Eureka Client

  • pom.xml
    依赖
    注意:新版本无spring-boot-starter-web依赖会出现下图错误,导致无法注册
    错误
  • 启动类注解
@SpringBootApplication
@EnableDiscoveryClient
public class ProductApplication {
    public static void main(String[] args) {
        SpringApplication.run(ProductApplication.class,args);
    }
}
  • application.yml
    配置

效果图

在这里插入图片描述
在这里插入图片描述

未完待续…

发布了7 篇原创文章 · 获赞 6 · 访问量 147

猜你喜欢

转载自blog.csdn.net/weixin_45319877/article/details/99119143