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包


posted @ 2018-10-16 06:39  忧臣解读  阅读(14962)  评论(3编辑  收藏  举报