`
zweichxu
  • 浏览: 134035 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

spring cloud版本升级记录(1)注册中心升级到Hoxton.SR12

 
阅读更多

     2018年开始做spring cloud微服务,选定版本是Finchley.RC2,时至今日,spring cloud版本从Finchley经历了GreenWich、Hoxton、2020.0.x、2021.0.x的变化,每一个版本的变化,使用的组件都有大的改变。Spring Cloud netflix中的zuul, ribbon, hystrix都基本上算是废了。

     zuul改用spring cloud gateway, Hystrix 直接改用Spring Cloud Circuit Breaker + Resilience4J,Ribbon改用 Spring Cloud Load Balancer.

     本次升级到spring cloud Hoxton.SR12,spring boot版本升级到2.3.12.RELEASE,仍然使用eureka server,服务发现服务的升级很简单,只需要更改spring cloud和spring boot的版本号即可。

pom.xml文件:

 

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.3.12.RELEASE</version>
  </parent>
  <groupId>net.hzwei206.test</groupId>
  <artifactId>sctest-discovery-server</artifactId>
  <version>0.0.2</version>
  <description>sctest-discovery-server</description>
  <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
     <java.version>1.8</java.version>
  </properties>
 
  <repositories>  
     <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/libs-milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
     </repository>
  </repositories> 
  <dependencyManagement>
     <dependencies>
         <dependency>
             <groupId>org.springframework.cloud</groupId>
             <artifactId>spring-cloud-dependencies</artifactId>
             <version>Hoxton.SR12</version>
             <type>pom</type>
             <scope>import</scope>
         </dependency>
     </dependencies>
  </dependencyManagement>
  <dependencies> 
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
          <exclusions>
              <exclusion>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-starter-tomcat</artifactId>
              </exclusion>
          </exclusions>
      </dependency>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-undertow</artifactId>
      </dependency>
      <dependency>
          <groupId>org.springframework.cloud</groupId>
	      <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
      </dependency> 
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-security</artifactId>
      </dependency>
      <dependency>
			<groupId>commons-io</groupId>
			<artifactId>commons-io</artifactId>
			<version>2.4</version> 
	  </dependency>
	  <dependency>
          <groupId>org.apache.httpcomponents</groupId>
          <artifactId>httpclient</artifactId> 
    </dependency>
  </dependencies>
  
  <build>
      ........
  </build>
</project>

   这里我弃用tomcat,改用undertow

 

 

   增加spring security:

 

 

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;

@EnableWebSecurity
public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.formLogin().defaultSuccessUrl("/")
            .and().httpBasic()
            .and()
            .authorizeRequests()
            .antMatchers("/login").permitAll()
            .anyRequest()
            .authenticated()
            .and().headers().frameOptions().disable()
            .and().csrf().disable();
    }
}

   .httpBasic()不能少,不然访问不了注册中心,服务无法注册。

 

 application.yml配置文件增加spring security的用户名密码:

    

server:
  port: 8761
spring:
  application:
    name: service-discovery-server
  security:
    basic:
      enabled: true
    user:
      name: admin
      password: 123456

   eureka-server配置:

   

eureka:
  server:
    enable-self-preservation: false
    eviction-interval-timer-in-ms: 4000
  instance:
    prefer-ip-address: true
    hostname: 127.0.0.1
  client:
    # 如果是集群,下面两个改为true
    register-with-eureka: false
    fetch-registry: false
    serviceUrl:
      defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@127.0.0.1:${server.port}/eureka/

 

 

    

分享到:
评论

相关推荐

    springcloud_入门示例_Hoxton.SR8.zip

    使用的是springcloud的Hoxton.SR8版本,idea工程,下载即可使用。适用于入门快速看效果。整合了eureka(注册中心)、Zuul(网关)、Feign(本地化的远程调研、负载均衡)、hystrix(熔断器)。笔记可查看:...

    商家及其消费者模式springcloud+eureka(多个)+ribbon(多个)

    2、springcloud(Hoxton.SR12,记得与其他spring版本相对应,否则项目启动不了) 3、eureka server(即是中间站,多个eureka,防止其中一个失效) 4、ribbon一个springcloud布置与多台电脑上(多个provider,缓解...

    Springboot+SpringCloud微服务架构demo

    在本项目中,"Springboot+SpringCloud微服务架构demo"是基于Spring Boot 2.2.2.RELEASE和Spring Cloud Hoxton.SR1构建的一个基础微服务示例,旨在帮助初学者理解和掌握Spring Cloud的相关概念和技术。下面将详细阐述...

    SpringBoot、SpringCloud、SpringCloud alibaba版本对应.docx

    例如,Spring Cloud的Hoxton.SR12版本需要Spring Boot在2.2.0.RELEASE和2.4.0.M1之间,而2020.0.3版本则要求Spring Boot在2.4.0.M1及更高版本但低于2.5.5-SNAPSHOT。这种对应关系对于确保各个组件之间的兼容性和稳定...

    spring boot、spring cloud、spring boot Alibaba以及配套组件版本关系

    - `2021.1`:对应Spring Cloud 2020.0.1,Spring Boot 2.4.2 这个分支主要针对那些使用Spring Boot 2.4及以下版本的企业级项目。 ##### 3. 2.2.x 分支 - **适配Spring Boot版本**:2.4 - **适配Spring Cloud版本*...

    SpringCloudHoxton.zip

    Spring Cloud Hoxton是Spring Cloud框架的一个版本,它包含了多个微服务相关的组件,用于构建分布式系统。这个压缩包“SpringCloudHoxton.zip”可能是为了帮助开发者快速搭建一个基于Spring Cloud Hoxton的微服务...

    Spring Cloud Gateway 实现代码

    2. 基于spring-boot 的2.3.12.RELEASE版本, spring-cloud的Hoxton.SR12版本,spring-cloud-alibaba的2.2.8.RELEASE版本 3. Spring Cloud Gateway版本为2.2.9.RELEASE版本 4. 代码需配合Nacos一起使用

    Spring Boot 2.3.12框架集成:全面配置与依赖版本管理

    依赖版本包括Spring Boot 2.3.12版本,Spring Cloud Hoxton.SR12,Spring Cloud Alibaba 2.2.10-RC1等。此外还包括MyBatis Plus 3.5.3.1、MySQL驱动8.0.19、Lombok 1.18.28以及一系列实用工具库如Hutool 5.8.21、...

    SpringCloudAlibaba环境搭建

    1,SpringCloudAlibaba环境搭建 2,SpringCloudAlibaba版本选择2.2.7.RELEASE 3,Spring Cloud Version选择Spring Cloud Hoxton.SR12 4,Spring Boot Version选择2.3.12.RELEASE

Global site tag (gtag.js) - Google Analytics