spring boot 2.0.4 配置一个简单的 eureka 带账号密码的 注册中心

step 1 , 创建maven工程

引入 pom 依赖

	<parent>
	    <groupId>org.springframework.boot</groupId>
	    <artifactId>spring-boot-starter-parent</artifactId>
	    <version>2.0.4.RELEASE</version>
	    <relativePath/>
	</parent>
	
	 <properties>
         <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		 <java.version>1.8</java.version>
		 <global.version>1.0.0</global.version>
	</properties>
	
	<dependencies>
	    <dependency>
	        <groupId>org.springframework.boot</groupId>
	        <artifactId>spring-boot-starter-test</artifactId>
	        <scope>test</scope>
	    </dependency>
	    <dependency>
	        <groupId>org.projectlombok</groupId>
	        <artifactId>lombok</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>

step 2 , 引入eureka server需要的依赖

  <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>

step 3 , 启动类配置

@EnableEurekaServer
@SpringBootApplication
public class RegisterCenterApplication {

	public static void main(String[] args) {

		SpringApplication.run(RegisterCenterApplication.class, args);
	}

}

step 4 , 配置security 类

@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
 
    @Override
    protected void configure(HttpSecurity http) throws Exception {
	    http.csrf().disable();//关闭csrf
	    super.configure(http);
    }
}

step 5 , YML 文件的配置

#========================
#========================
# 独立的服务器配置
#========================
#========================
spring:
   application:
      name: eureka-center
   security:
      user:
         name: test001
         password: test001
#服务注册中心端口号 
server:
   port: 8761
eureka:
   instance:
      #服务注册中心实例的主机名
      hostname: eureka-center
      prefer-ip-address: true
   client:
      serviceUrl:
         defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@192.168.0.114:${server.port}/eureka/
      #是否向服务注册中心注册自己  
      register-with-eureka: false  
      #是否检索服务
      fetch-registry: false

step 6 ,运行 application 文件 启动程序

2019-12-30 22:44:54.162  INFO 15348 --- [      Thread-13] o.s.c.n.e.server.EurekaServerBootstrap   : Initialized server context
2019-12-30 22:44:54.162  INFO 15348 --- [      Thread-13] c.n.e.r.PeerAwareInstanceRegistryImpl    : Got 1 instances from neighboring DS node
2019-12-30 22:44:54.163  INFO 15348 --- [      Thread-13] c.n.e.r.PeerAwareInstanceRegistryImpl    : Renew threshold is: 1
2019-12-30 22:44:54.163  INFO 15348 --- [      Thread-13] c.n.e.r.PeerAwareInstanceRegistryImpl    : Changing status to UP
2019-12-30 22:44:54.168  INFO 15348 --- [      Thread-13] e.s.EurekaServerInitializerConfiguration : Started Eureka Server
2019-12-30 22:44:54.181  INFO 15348 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8761 (http) with context path ''
2019-12-30 22:44:54.182  INFO 15348 --- [           main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 8761
2019-12-30 22:44:54.184  INFO 15348 --- [           main] com.grantz.RegisterCenterApplication     : Started RegisterCenterApplication in 9.796 seconds (JVM running for 10.363)

step 7 ,输入地址查看注册中心服务

url: localhost:8761 账号密码: test001

在这里插入图片描述
登录成功页面:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值