将微服务注册到Eureka Server上

一 编辑pom.xml文件


  4.0.0
  com.itmuch.cloud
  microservice-provider-user
  0.0.1-SNAPSHOT
  jar
  
  
    org.springframework.boot
    spring-boot-starter-parent
    1.4.3.RELEASE
  
  
    UTF-8
    1.8
  
  
    
      org.springframework.boot
      spring-boot-starter-web
    
    
      org.springframework.boot
      spring-boot-starter-data-jpa
    
    
      com.h2database
      h2
    
    
      org.springframework.boot
      spring-boot-starter-actuator
    
    
      org.springframework.cloud
      spring-cloud-starter-eureka
    
  
  
  
    
      
        org.springframework.cloud
        spring-cloud-dependencies
        Camden.SR4
        pom
        import
      
    
  
  
  
    
      
        org.springframework.boot
        spring-boot-maven-plugin
      
    
  
二 配置application.yml
server:
  port: 8000
spring:
  application:
    name: microservice-provider-user
  jpa:
    generate-ddl: false
    show-sql: true
    hibernate:
      ddl-auto: none
  datasource:                           # 指定数据源
    platform: h2                        # 指定数据源类型
    schema: classpath:schema.sql        # 指定h2数据库的建表脚本
    data: classpath:data.sql            # 指定h2数据库的数据脚本
logging:                                # 配置日志级别,让hibernate打印出执行的SQL
  level:
    root: INFO
    org.hibernate: INFO
    org.hibernate.type.descriptor.sql.BasicBinder: TRACE
    org.hibernate.type.descriptor.sql.BasicExtractor: TRACE
eureka:
  client:
    serviceUrl:
      defaultZone:http://localhost:8761/eureka/
  instance:
    prefer-ip-address: true
三 编写启动类
package com.itmuch.cloud.study;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@EnableDiscoveryClient
@SpringBootApplication
public class ProviderUserApplication {
  public static void main(String[] args) {
    SpringApplication.run(ProviderUserApplication.class, args);
  }
}
四 测试
将微服务注册到Eureka Server上_第1张图片

你可能感兴趣的:(微服务)