spring-cloud项目搭建(一)

搭建Eureka服务发现中心 

项目源码:https://gitee.com/lwydyby/springcloud-adplatform

maven搭建有两种方式:

(1)使用idea直接搭建spring-io的springcloud项目

(2)直接创建普通maven项目,自己配置pom.xml (该文章使用这种方式)

pom.xml:



	4.0.0

	com.gameley
	eureka-server
	jar
	eureka-server


	
		com.gameley
		adplatform
		1.0.0-SNAPSHOT
	


	
		
			org.springframework.cloud
			spring-cloud-starter-eureka-server
		
		
			org.springframework.boot
			spring-boot-starter-web
			
				
					org.springframework.boot
					spring-boot-starter-tomcat
				
			
		
		
			org.springframework.boot
			spring-boot-starter-jetty
		
		
			org.springframework.boot
			spring-boot-starter-actuator
		
	

	
		
			
				org.springframework.boot
				spring-boot-maven-plugin
			
			
				com.spotify
				docker-maven-plugin
				0.4.13
				
					
						package
						
							build
						
					
				
				
					gameley/eureka
					${project.basedir}/src/main/docker
					
						
							/
							${project.build.directory}
							${project.build.finalName}.jar
						
					
				
			
		

	



本项目使用了jetty替代tomcat,docker-maven-plugin为后边搭建docker镜像使用(暂时可以忽略),spring-boot-starter-actuator为更详细的监控引入
创建EurekaServerApplication启动类:
package com.gameley;

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

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

	public static void main(String[] args) {
		SpringApplication.run(EurekaServerApplication.class, args);
	}
}

 配置文件 application.yml: 
  

server:
  port: 8761

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




 
 

你可能感兴趣的:(springcloud项目搭建)