springCloud 学习第三篇——构建第二个服务,并注册到eureka注册中心

复制上一篇创建好的项目,重新构建spring-boot项目:md-service-cud;替换pom.xml文件;

项目目录:

springCloud 学习第三篇——构建第二个服务,并注册到eureka注册中心_第1张图片

一:pom.xml



    4.0.0

    com.example
    md-service-cud
    0.0.1-SNAPSHOT
    jar

    md-service-cud
    Demo project for Spring Boot

    
        org.springframework.boot
        spring-boot-starter-parent
        1.5.2.RELEASE
         
    
    
        UTF-8
        UTF-8
        1.8
    

    
        
            org.springframework.cloud
            spring-cloud-starter-eureka
        
        
            org.springframework.cloud
            spring-cloud-starter-config
        
        
            org.springframework.cloud
            spring-cloud-bus
        
        
            org.springframework.cloud
            spring-cloud-stream-binder-rabbit
        
        
            org.springframework.boot
            spring-boot-starter-actuator
        
        
            org.springframework.boot
            spring-boot-starter-amqp
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
            io.springfox
            springfox-swagger2
            2.6.1
        
        
            io.springfox
            springfox-swagger-ui
            2.6.1
        
        
            org.projectlombok
            lombok
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            1.3.0
        
        
            mysql
            mysql-connector-java
        
        
            com.alibaba
            druid
            1.1.5
        
        
            com.alibaba
            fastjson
            1.2.30
        
    
    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                Dalston.RC1
                pom
                import
            
        
    
    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    
    
        
            spring-milestones
            Spring Milestones
            https://repo.spring.io/milestone
            
                false
            
        
    

二:MdServiceCudApplication 

package com.example.mdservicecud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@EnableEurekaClient
@ComponentScan
@RestController
public class MdServiceCudApplication {

    public static void main(String[] args) {
        SpringApplication.run(MdServiceCudApplication.class, args);
    }
    @GetMapping("/service")
    public String service(){
        return "service-c";
    }
}

三:application.yml

server:
  port: 8763
spring:
  application:
    name: md-service-cud

四:bootstrap.yml

spring:
  profiles:
    active: dev
  cloud:
      config:
         fail-fast: true
         discovery:
            service-id: md-config-server
            enabled: true
      bus:
        trace:
            enabled: true
        enabled: true

eureka:
  client:
    serviceUrl:
           defaultZone: http://localhost:8861/eureka/

management:
  security:
    enabled: false

五:bean/user:

package com.example.mdservicecud.bean;

import java.util.Date;

import lombok.Data;
import lombok.ToString;

@Data 
@ToString
public class User {

	private int id;
	private String username;
	private int age;
	// Getter Setter
}

六:MyController、UserController

package com.example.mdservicecud.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RefreshScope
@RestController
@RequestMapping("/myTest")
public class MyController {

    @Value("${foo}")
    String foo;

    @RequestMapping("/foo")
    public String hi(){
        return foo;
    }
}
package com.example.mdservicecud.controller;

import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import  com.example.mdservicecud.bean.User;
import java.util.*;

@RestController
@RequestMapping("/user")
public class UserController {
	// 创建线程安全的Map,用于承接user对象数据,模拟增删改查
	static Map users = Collections.synchronizedMap(new HashMap());

	@ApiIgnore//使用该注解忽略这个API
	@RequestMapping(value = "/say", method = RequestMethod.GET)
	public String  jsonTest() {
		return " say : hello spring boot!";
	}
}

 

你可能感兴趣的:(springCloud)