一、springcloud注册中心

1、pom文件

<?xml version="1.0" encoding="UTF-8"?>
<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>
        <artifactId>springcloud-fang</artifactId>
        <groupId>com.fangj.springcloud.core</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
  <artifactId>fang-registry</artifactId>
  <packaging>jar</packaging>
  <name>fang-registry</name>
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <dependencies>
   		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-eureka-server</artifactId>
		</dependency>
  </dependencies>

  <build>
		<plugins>
			<plugin>
			   <groupId>com.spotify</groupId>
			   <artifactId>docker-maven-plugin</artifactId>
			   <version>0.4.12</version>
			   <configuration>
			      <!-- 注意imageName一定要是符合正则[a-z0-9-_.]的,否则构建不会成功 -->
			      <!-- 详见:https://github.com/spotify/docker-maven-plugin    Invalid repository name ... only [a-z0-9-_.] are allowed-->
			      <dockerHost>https://192.168.1.122:2375</dockerHost>
			      <dockerCertPath>/Users/kenkou/.docker/machine/machines/default</dockerCertPath>
			      <imageName>fangj:0.0.1</imageName>
			      <dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
			      <resources>
			         <resource>
			            <targetPath>/</targetPath>
			            <directory>${project.build.directory}</directory>
			            <include>${project.build.finalName}.jar</include>
			         </resource>
			      </resources>
			   </configuration>
			</plugin>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>
  
</project>

  2、配置文件

 application.properties

#eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false

  application.yml

server:
  port: 8761
  #官方写的就是 8761
spring:
  application:
    name: eureka-server

eureka:
  instance:
    hostname: eureka-server
    #配置主机名
  client:
    register-with-eureka: false
    #配置服务注册中心是否以自己为客户端进行注册(配置false)
    fetch-registry: false
    #是否取得注册信息(配置false)
    service-url:
      default-zone: http://${eureka.instance.hostname}:${server.port}/eureka/
      #配置eureka客户端的缺省域(该配置可能没有提示,请复制或者手动输入,切勿使用有提示的service-url会引起内置tomcat报错)

  3、启动类

package com.fangj.springcloud.core;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

/**  
 * 注册中心
 *  
 * @author Jimmy.Fang
 * @date 2017年12月28日  新建  
 */
@EnableEurekaServer
@SpringBootApplication
public class EurekaRegisterApplication {
	/**
	 * 入口程序
	 * @param args
	 */
	public static void main(String[] args) {
		new SpringApplicationBuilder(EurekaRegisterApplication.class).run(args);
	}
}

  

posted @ 2018-06-26 15:35  方坚.cn  阅读(255)  评论(0编辑  收藏  举报