美文网首页
springcloud-Finchley.SR1

springcloud-Finchley.SR1

作者: 霹雳解锋镝 | 来源:发表于2018-10-12 23:33 被阅读0次

    主依赖

    <groupId>com.lh</groupId>
    <artifactId>mypinyougou</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    
    <name>mypinyougou</name>
    <description>Demo project for Spring Boot</description>
    
    <modules>
        <module>manager-ui</module>
        <module>manager-server</module>
        <module>pinyougou-common</module>
        <module>eureka-server</module>
    </modules>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
    
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.SR1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    

    eureka-server依赖

    <groupId>com.lh</groupId>
    <artifactId>eureka-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    
    <name>eureka-server</name>
    <description>Demo project for Spring Boot</description>
    <parent>
        <groupId>com.lh</groupId>
        <artifactId>mypinyougou</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>
    

    eureka-server application.yml

    spring:
      application:
        name: manager-server #服务名称
    server:
      port: 9002 #启动端口号
    eureka:
      client:
        register-with-eureka: true #是否注册到eureka服务器
        fetch-registry: true #是否可检索
        service-url:
          defaultZone: http://127.0.0.1:9001/eureka/ #服务中心
    

    eureka-server代码

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

    manager-ui依赖

        <groupId>com.lh</groupId>
    <artifactId>manager-ui</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    
    <name>manager-ui</name>
    <description>Demo project for Spring Boot</description>
    <parent>
        <groupId>com.lh</groupId>
        <artifactId>mypinyougou</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
        <dependency>
            <groupId>com.pinyougou</groupId>
            <artifactId>pinyougou-common</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
    

    manager-ui的application.yml

    spring:
      application:
        name: manager-ui #服务名称
    server:
      port: 9003 #启动端口号
    eureka:
      client:
        register-with-eureka: true #是否注册到eureka服务器
        fetch-registry: true #是否可检索
        service-url:
          defaultZone: http://127.0.0.1:9001/eureka/ #服务中心
    

    manager-ui的启动方法

    @SpringBootApplication
    @EnableEurekaClient
    @EnableFeignClients // 调用服务提供方时启用负载均衡
    public class ManagerUiApplication {
        public static void main(String[] args) {
        SpringApplication.run(ManagerUiApplication.class, args);
      }
    }
    

    注意 :This will cause @Autowired to not work because there isn’t exactly one bean, or one marked as primary. To work around this, Spring Cloud Netflix marks all Feign instances as @Primary如下:

     @FeignClient(name = "manager-server", primary = false)
    

    其他资源参考:
    springcloud
    https://blog.csdn.net/qq_42606051/article/details/81776303

    相关文章

      网友评论

          本文标题:springcloud-Finchley.SR1

          本文链接:https://www.haomeiwen.com/subject/dtenaftx.html