springCloud当中Eureca消费者Consumer的部署

消费者的部署:
马克- to-win:马克 java社区:防盗版实名手机尾号: 73203。



做个普通的maven project,quickstart archetype。改成jdk.8。过去我们都是:

@Service
public class LoginServiceImpl2 implements ILoginService {
    public void login() {
        System.out.println("LoginServiceImpl2");
    }
}

我们的注解过去都写在类前面,而这次,如下图,注解写在了方法上,意味着,告诉Spring容器,运行以下方法,得到一个Bean实例,放在Spring容器中,以备将来调用:

    @Bean
    public RestTemplate restTemplate () {
        return new RestTemplate ();
    }

pom.xml:




<?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">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com</groupId>
    <artifactId>eurekaMaven</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

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

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

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Camden.SR2</version>
                 <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
    </dependencies>
</project>





application.yml:

server:
  port: 9000   
 
spring:
  application:
    name: myConsumer
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/