zoukankan      html  css  js  c++  java
  • SpringBoot2.x搭建Eureka

    1 说明

    1. 全部配置基于1.8.0_111
    2. 当前SpringBoot使用2.0.5

    2 创建项目

    SpringBoot项目生成器中,输入GroupArtifact,如下配置:

    3 pom.xml配置

    pom.xml文件中,加入以下:

    <properties>
            <spring-cloud.version>Finchley.SR1</spring-cloud.version>
    </properties>
    <dependencies>
            <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>
    </dependencies>
    <dependencyManagement>
    		<dependencies>
    			<dependency>
    				<groupId>org.springframework.cloud</groupId>
    				<artifactId>spring-cloud-dependencies</artifactId>
    				<version>${spring-cloud.version}</version>
    				<type>pom</type>
    				<scope>import</scope>
    			</dependency>
    		</dependencies>
    	</dependencyManagement>
    

    4 配置application.yml文件

    修改application.propertiesapplication.yml文件,加入以下:

    server:
      port: 8888
    spring:
      application:
        name: eurka-server
      security:
        user:
          name: anxminise
          password: 123456
    eureka:
      client:
        registerWithEureka: false
        fetchRegistry: false
        serviceUrl:
          defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@127.0.0.1:${server.port}/eureka/
    

    5 编辑SpringBootEurekaApplication.java文件

    编辑SpringBootEurekaApplication.java,如下:

    @EnableEurekaServer
    @SpringBootApplication
    public class SpringBootEurekaApplication {
    
    	public static void main(String[] args) {
    		SpringApplication.run(SpringBootEurekaApplication.class, args);
    	}
    
    	@EnableWebSecurity
    	public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
    		@Override
    		protected void configure(HttpSecurity http) throws Exception {
    			http.csrf().disable();
    			super.configure(http);
    		}
    	}
    }
    

    6 启动eureka

    执行以下命令,进行构建并启动:

    ./mvnw clean package -DskipTests #构建可直接运行的jar包
    java -jar target/SpringBootEureka-0.0.1-SNAPSHOT.jar #启动jar包
    


  • 相关阅读:
    leetcode-15 三数之和
    leetcode-113 路径之和
    leetcode-112 路径之和
    leetcode-1 两数之和
    leetcode-215 第k大元素
    leetcode 698 集合k划分
    编程之法之字符串
    LeetCode 830. Positions of Large Groups
    LeetCode 821. Shortest Distance to a Character
    LeetCode 213. House Robber II
  • 原文地址:https://www.cnblogs.com/anxminise/p/9789075.html
Copyright © 2011-2022 走看看