spring cloud (一、服务注册demo_eureka)

        首先我的博客记理论知识很少,大家对spring boot、spring cloud  、分布式 、微服务什么的一点概念都没有的还请先去百度看看理论,知道了是做什么用的,然后再写下demo ,这样学起来才没有那么迷糊!

        我一般写下的demo都是我踩了很多坑,或者说很多人在其他地方写下的demo搬过来根本运行不起来,然后我经过处理和查询,整理了一下!

        方便我以后再回来查找,也方便有些小伙伴入门的demo!

        我就简略的介绍一个这个demo;就是spring cloud 中的一个注册服务器 、注册管理中心 会自动监控!

        这个demo是我从官网上面找下来的,然后注释了一些用不上的代码和配置!

       我这里采用的idea编辑器!

        第一步:我们建立一个spring boot项目 

         如下图:一直next.......最后Finish

  

spring cloud (一、服务注册demo_eureka)

     

 

        第二步:修改maven的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 "> <modelVersion>4.0.0</modelVersion><!--描述这个POM文件是遵从哪个版本的项目描述符。--> <groupId>com.example</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>demo</name> <description>demo project for Spring Boot</description> <parent><!--父级依赖,继承--> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <dependencies><!--引入依赖--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <!--声明依赖,如果dependencies中没有声明版本就会来这里面找--> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Finchley.BUILD-SNAPSHOT</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <properties><!--定义的标签属性可以在其他地方读取--> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <start-class>com.example.demo.DemoApplication</start-class> <java.version>1.8</java.version> <!-- <docker.image.prefix>springcloud</docker.image.prefix>--> </properties> <build> <plugins> <!-- <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.2.3</version> <configuration> <baseImage>openjdk:8-jre-alpine</baseImage> <imageName>${docker.image.prefix}/${project.artifactId}</imageName> <exposes>8761</exposes> <entryPoint>["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/${project.build.finalName}.jar"]</entryPoint> <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> &lt;!&ndash; defined in spring-cloud-starter-parent pom (as documentation hint), but needs to be repeated here &ndash;&gt; <configuration> <requiresUnpack> <dependency> <groupId>com.netflix.eureka</groupId> <artifactId>eureka-core</artifactId> </dependency> <dependency> <groupId>com.netflix.eureka</groupId> <artifactId>eureka-client</artifactId> </dependency> </requiresUnpack> </configuration> </plugin>--> <!-- <plugin> <groupId>pl.project13.maven</groupId> <artifactId>git-commit-id-plugin</artifactId> <configuration> <failOnNoGitDirectory>false</failOnNoGitDirectory> </configuration> </plugin> <plugin> &lt;!&ndash;skip deploy (this is just a test module) &ndash;&gt; <artifactId>maven-deploy-plugin</artifactId> <configuration> <skip>true</skip> </configuration> </plugin>--> </plugins> </build> <!-- &lt;!&ndash;相当于配置远程仓库&ndash;&gt; <repositories> <repository> <id>spring-snapshots</id> <name>Spring Snapshots</name> <url>https://repo.spring.io/libs-snapshot</url> &lt;!&ndash;是否自动更新&ndash;&gt; <snapshots> <enabled>true</enabled> </snapshots> </repository> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/libs-milestone</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>spring-releases</id> <name>Spring Releases</name> <url>https://repo.spring.io/libs-release</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> &lt;!&ndash;插件仓库&ndash;&gt; <pluginRepositories> <pluginRepository> <id>spring-snapshots</id> <name>Spring Snapshots</name> <url>https://repo.spring.io/libs-snapshot-local</url> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> <pluginRepository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/libs-milestone-local</url> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories>--> </project>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsfjdp.html