SpringCloud项目搭建(一) 父工程与Eureka server --从零开始


为什么学习SpringCloud? SpringCloud是基于SpringBoot,提供了完整的微服务解决方案,包含了众多组件,是目前很火的微服务框架。

选择的编辑器IDEA 那么开始吧^^*:

1.创建父项目

   选maven->next

 取个名

现页面:

 

2.Eureka server

 

 

 

取个名字

 

 请选择 Eureka Server

 

 这个不用改

 

finish->

 

改成了yml文件

代码:

spring:
  application:
    name: eureka-server
  security:
    user:
      name: user
      password: 123456
server:
  port: 8890
eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false

    serviceUrl:
      defaultZone: http://user:123456@localhost:8890/eureka/
  server:
    renewalPercentThreshold: 0.49
View Code

加注解  @EnableEurekaServer 

 debug 启动测试一下:

浏览器页面测试:

让账号密码起作用:+

       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

展示结果

 

***当加了密码之后起client 起不来时:

package com.cloud.eurekaserver.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter{

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER);
        http.csrf().disable();
        http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
    }
}
View Code


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM