SpringCloud-01-Eureka注册中心搭建

分手后的思念是犯贱 2022-05-26 13:22 273阅读 0赞
  1. 开发环境:ideaeclipse均可。

pom文件配置:

  1. <parent>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-parent</artifactId>
  4. <version>1.4.3.RELEASE</version>
  5. <relativePath/> <!-- lookup parent from repository -->
  6. </parent>
  7. <properties>
  8. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  9. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  10. <java.version>1.8</java.version>
  11. </properties>
  12. <dependencies>
  13. <!--eureka server -->
  14. <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-eureka-server -->
  15. <dependency>
  16. <groupId>org.springframework.cloud</groupId>
  17. <artifactId>spring-cloud-starter-eureka-server</artifactId>
  18. </dependency>
  19. <!-- spring boot test-->
  20. <dependency>
  21. <groupId>org.springframework.boot</groupId>
  22. <artifactId>spring-boot-starter-test</artifactId>
  23. <scope>test</scope>
  24. </dependency>
  25. <dependency>
  26. <groupId>org.springframework.boot</groupId>
  27. <artifactId>spring-boot-autoconfigure</artifactId>
  28. </dependency>
  29. </dependencies>
  30. <dependencyManagement>
  31. <dependencies>
  32. <dependency>
  33. <groupId>org.springframework.cloud</groupId>
  34. <artifactId>spring-cloud-dependencies</artifactId>
  35. <version>Camden.SR3</version>
  36. <type>pom</type>
  37. <scope>import</scope>
  38. </dependency>
  39. </dependencies>
  40. </dependencyManagement>
  41. <build>
  42. <plugins>
  43. <plugin>
  44. <groupId>org.springframework.boot</groupId>
  45. <artifactId>spring-boot-maven-plugin</artifactId>
  46. </plugin>
  47. </plugins>
  48. </build>
  49. <repositories>
  50. <repository>
  51. <id>spring-milestones</id>
  52. <name>Spring Milestones</name>
  53. <url>https://repo.spring.io/milestone</url>
  54. <snapshots>
  55. <enabled>false</enabled>
  56. </snapshots>
  57. </repository>
  58. </repositories>

对应的application文件配置:application.yml

  1. server:
  2. port: 8761
  3. eureka:
  4. instance:
  5. hostname: localhost
  6. client:
  7. registerWithEureka: false
  8. fetchRegistry: false
  9. serviceUrl:
  10. defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

用idea基本上基础代码都会生成:

  1. package com.example.eurekaserver;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
  5. @EnableEurekaServer
  6. @SpringBootApplication
  7. public class EurekaserverApplication {
  8. public static void main(String[] args) {
  9. SpringApplication.run(EurekaserverApplication.class, args);
  10. }
  11. }

直接springboot run就可以了。

注意点:我在测试注册中心的时候出现的两个错误,错误代码就不贴了。

1.配置文件名一定要写正确,配置项也要相应正确;

2.对应错误代码:

  1. com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect

上面给的pom文件是我测试过的应该没错,但是报上面错的原因是:springboot和cloud的版本,版本,版本(

  1. 1.4.3.RELEASECamden.SR3 是可以对上的,其他版本自测去。

发表评论

表情:
评论列表 (有 0 条评论,273人围观)

还没有评论,来说两句吧...

相关阅读