赞
踩
eureka是个什么东西呢?它是一个服务注册中心。就拿电商系统的例子来说,如果要查看会员的订单详情,那么就要在会员系统的tomcat里面调用订单系统的tomcat里的方法。那么直接通过接口访问吗?显然这是不安全的。因此我们需要一个统一管理远程RPC调用的注册中心。
- <parent>
- <artifactId>bg-cloud</artifactId>
- <groupId>com.bg</groupId>
- <version>1.0-SNAPSHOT</version>
- </parent>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <maven.compiler.source>1.7</maven.compiler.source>
- <maven.compiler.target>1.7</maven.compiler.target>
- <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
- </properties>
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
- </dependency><dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-dependencies</artifactId>
- <version>${spring-cloud.version}</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- </dependencies>
- </dependencyManagement>
- @SpringBootApplication
- @EnableEurekaServer
- public class EurekaServerApplication{
-
- public static void main(String[] args) {
- SpringApplication.run(EurekaServerApplication.class, args );
- }
- }
- # 本身是注册中心,但是也需要注册,这里可以向自己注册
- server:
- port: 9000
- eureka:
- instance:
- prefer-ip-address: true
- hostname: localhost
- client:
- service-url:
- defaultZone: http://http://${eureka.instance.hostname}:${server.port}/eureka/
- # 不在页面上显示当前 服务
- register-with-eureka: false
- # 为true时,可以启动,但报异常:Cannot execute request on any known server
- fetch-registry: false
- # 服务名 ,很重要 ,后期 config 配置中心会以 服务名为标识找对应的 服务
- spring:
- application:
- name: eureka-server
- # 设置当前项目端口号
- <?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">
- <parent>
- <artifactId>bg-cloud</artifactId>
- <groupId>com.bg</groupId>
- <version>1.0-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
- <artifactId>bg-cloud-user</artifactId>
- <packaging>war</packaging>
- <name>bg-cloud-user Maven Webapp</name>
- <!-- FIXME change it to the project's website -->
- <url>http://www.example.com</url>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <maven.compiler.source>1.7</maven.compiler.source>
- <maven.compiler.target>1.7</maven.compiler.target>
- </properties>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot</artifactId>
- <version>2.1.4.RELEASE</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-autoconfigure</artifactId>
- <version>2.1.4.RELEASE</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- <version>2.1.4.RELEASE</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
- </dependency>
-
- </dependencies>
-
- <build>
- <finalName>bg-cloud-user</finalName>
- <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
- <plugins>
- <plugin>
- <artifactId>maven-clean-plugin</artifactId>
- <version>3.1.0</version>
- </plugin>
- <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
- <plugin>
- <artifactId>maven-resources-plugin</artifactId>
- <version>3.0.2</version>
- </plugin>
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.8.0</version>
- </plugin>
- <plugin>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.22.1</version>
- </plugin>
- <plugin>
- <artifactId>maven-war-plugin</artifactId>
- <version>3.2.2</version>
- </plugin>
- <plugin>
- <artifactId>maven-install-plugin</artifactId>
- <version>2.5.2</version>
- </plugin>
- <plugin>
- <artifactId>maven-deploy-plugin</artifactId>
- <version>2.8.2</version>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
- </project>
- @SpringBootApplication()
- @EnableEurekaClient
- public class UserApplication {
- public static void main(String[] args) {
- SpringApplication.run(UserApplication.class, args);
- }
- }
- eureka:
- prefer-ip-address: true
- instance:
- appname: eureka-server
- hostname: localhost
- client:
- registry-fetch-interval-seconds: 10
- fetchRegistry: true
- serviceUrl:
- defaultZone: http://localhost:9000/eureka
- server:
- port: 8000
- spring:
- application:
- name: user-server
- /**
- * @ClassName IndexController
- * @Description 描述此类用途
- * @Author lizhijun
- * @Date 2020/6/11 12:30
- * @Version V1.0
- **/
- @RestController
- @RequestMapping("/index")
- public class IndexController {
- @RequestMapping("/test")
- public String test(){
- System.out.println("经过了");
- retun "hello test 8000";
- }
-
- }
查看原文请进:http://www.sucai66.com/article/detail/20200617/20.html
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。