【Spring Cloud】一、Eureka Server 服务注册中心服务端启动

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://xxlcube.blog.csdn.net/article/details/78562936

 

 

 

无意中发现了一个巨牛的人工智能教程,忍不住分享一下给大家。教程不仅是零基础,通俗易懂,而且非常风趣幽默,像看小说一样!觉得太牛了,所以分享给大家。点这里可以跳转到教程。

 

 

 

建立maven工程

工程结构如下:

pom文件如下:

 

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

	<groupId>eureka</groupId>
	<artifactId>eureka</artifactId>
	<version>1.0</version>
	<packaging>jar</packaging>

	<name>eureka</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<java.version>1.8</java.version>
	</properties>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.3.RELEASE</version>
		<relativePath />
	</parent>


	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-eureka-server</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-starter-parent</artifactId>
				<version>Dalston.SR1</version>   <!--Brixton.SR3官网为Angel.SR4版本,但是我使用的时候总是报错 -->
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>
	<build>
		<finalName>eureka</finalName>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<configuration>
					<archive>
						<manifest>
							<mainClass>com.chiwei.eureka.Bootstrap</mainClass>
							<addClasspath>true</addClasspath>
							<classpathPrefix>lib/</classpathPrefix>
						</manifest>
						<manifestEntries>
							<Class-Path>./</Class-Path>
						</manifestEntries>
					</archive>
					<excludes>
						<exclude>config/**</exclude>
						<exclude>templates/**</exclude>
						<exclude>static/**</exclude>
					</excludes>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.jacoco</groupId>
				<artifactId>jacoco-maven-plugin</artifactId>
				<configuration>
					<excludes>

					</excludes>
				</configuration>
				<executions>
					<execution>
						<goals>
							<goal>prepare-agent</goal>
						</goals>
					</execution>
					<execution>
						<id>report</id>
						<phase>prepare-package</phase>
						<goals>
							<goal>report</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<artifactId>maven-source-plugin</artifactId>
				<configuration>
					<attach>true</attach>
				</configuration>
				<executions>
					<execution>
						<phase>compile</phase>
						<goals>
							<goal>jar</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<artifactId>maven-assembly-plugin</artifactId>
				<executions>
					<execution>
						<id>make-tgz</id>
						<!-- 绑定到package生命周期阶段上 -->
						<phase>package</phase>
						<goals>
							<!-- 绑定到package生命周期阶段上 -->
							<goal>single</goal>
						</goals>
						<configuration>
							<descriptors> <!--描述文件路径 -->
								<descriptor>assembly.xml</descriptor>
							</descriptors>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>${java.version}</source>
					<target>${java.version}</target>
					<encoding>${project.build.sourceEncoding}</encoding>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>


其中注意spring-boot-starter-parent和spring-boot-starter-parent的版本号要对应起来,否则运行可能报错,楼主踩过坑

 

配置文件中重要配置项如下:

 

#是否向服务注册中心注册自己
eureka.client.register-with-eureka=false
#是否检索服务
eureka.client.fetch-registry=false
#服务注册中心实例的主机名
eureka.instance.hostname=myinstance


logging.level.com.netflix.eureka=OFF
logging.level.com.netflix.discovery=OFF


#服务注册中心端口号
server.port=23456

启动代码如下:

 

 

package com.chiwei.eureka;

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

/**
 * @Type Bootstrap.java
 * @Desc 
 * @author chiwei
 * @date 2017年11月9日 下午5:24:53
 * @version 
 */
/**
 * @author chiwei
 *
 */

@EnableEurekaServer
@SpringBootApplication
public class Bootstrap {

    /**
     * 主函数入口
     * @param args
     */
    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(Bootstrap.class);
        // 不启动web服务
        // app.setWebEnvironment(false);
        app.run(args);
    }

}

/**
 * Revision history
 * -------------------------------------------------------------------------
 * 
 * Date Author Note
 * -------------------------------------------------------------------------
 * 2017年11月9日 chiwei create
 */

 

 

启动服务注册中心服务端



 

至此,eureka的服务注册中服务端启动成功了。

 

 

 

 

 

 

 

展开阅读全文

没有更多推荐了,返回首页