新增spring cloud用例
This commit is contained in:
		
							
								
								
									
										50
									
								
								spring-cloud/spring-cloud-feign/consumer/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								spring-cloud/spring-cloud-feign/consumer/pom.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,50 @@
 | 
			
		||||
<?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>
 | 
			
		||||
 | 
			
		||||
    <parent>
 | 
			
		||||
        <groupId>com.heibaiying.feign</groupId>
 | 
			
		||||
        <artifactId>spring-cloud-feign</artifactId>
 | 
			
		||||
        <version>0.0.1-SNAPSHOT</version>
 | 
			
		||||
    </parent>
 | 
			
		||||
 | 
			
		||||
    <artifactId>consumer</artifactId>
 | 
			
		||||
 | 
			
		||||
    <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.boot</groupId>
 | 
			
		||||
            <artifactId>spring-boot-starter-freemarker</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <!-- feign 依赖-->
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.springframework.cloud</groupId>
 | 
			
		||||
            <artifactId>spring-cloud-starter-openfeign</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <!--引入对公共模块的依赖-->
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.heibaiying.feign</groupId>
 | 
			
		||||
            <artifactId>common</artifactId>
 | 
			
		||||
            <version>0.0.1-SNAPSHOT</version>
 | 
			
		||||
            <scope>compile</scope>
 | 
			
		||||
        </dependency>
 | 
			
		||||
    </dependencies>
 | 
			
		||||
 | 
			
		||||
    <build>
 | 
			
		||||
        <plugins>
 | 
			
		||||
            <plugin>
 | 
			
		||||
                <groupId>org.springframework.boot</groupId>
 | 
			
		||||
                <artifactId>spring-boot-maven-plugin</artifactId>
 | 
			
		||||
            </plugin>
 | 
			
		||||
        </plugins>
 | 
			
		||||
    </build>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -0,0 +1,18 @@
 | 
			
		||||
package com.heibaiying.consumer;
 | 
			
		||||
 | 
			
		||||
import org.springframework.boot.SpringApplication;
 | 
			
		||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
 | 
			
		||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 | 
			
		||||
import org.springframework.cloud.openfeign.EnableFeignClients;
 | 
			
		||||
 | 
			
		||||
@SpringBootApplication
 | 
			
		||||
@EnableDiscoveryClient
 | 
			
		||||
@EnableFeignClients
 | 
			
		||||
public class ConsumerApplication {
 | 
			
		||||
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
        SpringApplication.run(ConsumerApplication.class, args);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,37 @@
 | 
			
		||||
package com.heibaiying.consumer.controller;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import com.heibaiying.common.bean.Product;
 | 
			
		||||
import com.heibaiying.consumer.feign.CProductFeign;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.stereotype.Controller;
 | 
			
		||||
import org.springframework.ui.Model;
 | 
			
		||||
import org.springframework.web.bind.annotation.PathVariable;
 | 
			
		||||
import org.springframework.web.bind.annotation.RequestMapping;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author : heibaiying
 | 
			
		||||
 */
 | 
			
		||||
@Controller
 | 
			
		||||
@RequestMapping("sell")
 | 
			
		||||
public class SellController {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private CProductFeign cproductFeign;
 | 
			
		||||
 | 
			
		||||
    @RequestMapping
 | 
			
		||||
    public String productList(Model model) {
 | 
			
		||||
        List<Product> products = cproductFeign.productList();
 | 
			
		||||
        model.addAttribute("products", products);
 | 
			
		||||
        return "products";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @RequestMapping("product/{id}")
 | 
			
		||||
    public String productDetail(@PathVariable int id, Model model) {
 | 
			
		||||
        Product product = cproductFeign.productDetail(id);
 | 
			
		||||
        model.addAttribute("product", product);
 | 
			
		||||
        return "product";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,13 @@
 | 
			
		||||
package com.heibaiying.consumer.feign;
 | 
			
		||||
 | 
			
		||||
import com.heibaiying.common.feign.ProductFeign;
 | 
			
		||||
import org.springframework.cloud.openfeign.FeignClient;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author : heibaiying
 | 
			
		||||
 * @description : 声明式接口调用
 | 
			
		||||
 */
 | 
			
		||||
@FeignClient("producer")
 | 
			
		||||
public interface CProductFeign extends ProductFeign {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
server:
 | 
			
		||||
  port: 8030
 | 
			
		||||
# 指定服务命名
 | 
			
		||||
spring:
 | 
			
		||||
  application:
 | 
			
		||||
    name: consumer
 | 
			
		||||
# 指定注册中心地址
 | 
			
		||||
eureka:
 | 
			
		||||
  client:
 | 
			
		||||
    serviceUrl:
 | 
			
		||||
      defaultZone: http://localhost:8010/eureka/
 | 
			
		||||
@@ -0,0 +1,15 @@
 | 
			
		||||
<!doctype html>
 | 
			
		||||
<html lang="en">
 | 
			
		||||
<head>
 | 
			
		||||
    <title>产品详情</title>
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
<ul>
 | 
			
		||||
    <li>产品名称:${product.name}</li>
 | 
			
		||||
    <li>产品序列号:${product.id}</li>
 | 
			
		||||
    <li>是否贵重品:${product.isPrecious?string('是','否')}</li>
 | 
			
		||||
    <li>生产日期: ${product.dateInProduced?string("yyyy-MM-dd HH:mm:ss")}</li>
 | 
			
		||||
    <li>产品价格:${product.price}</li>
 | 
			
		||||
</ul>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
@@ -0,0 +1,16 @@
 | 
			
		||||
<!doctype html>
 | 
			
		||||
<html lang="en">
 | 
			
		||||
<head>
 | 
			
		||||
    <title>产品列表</title>
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
<h3>产品列表:点击查看详情</h3>
 | 
			
		||||
<ul>
 | 
			
		||||
    <#list products as product>
 | 
			
		||||
       <li>
 | 
			
		||||
           <a href="sell/product/${product.id}">${product.name}</a>
 | 
			
		||||
       </li>
 | 
			
		||||
    </#list>
 | 
			
		||||
</ul>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
@@ -0,0 +1,17 @@
 | 
			
		||||
package com.heibaiying.consumer;
 | 
			
		||||
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
import org.junit.runner.RunWith;
 | 
			
		||||
import org.springframework.boot.test.context.SpringBootTest;
 | 
			
		||||
import org.springframework.test.context.junit4.SpringRunner;
 | 
			
		||||
 | 
			
		||||
@RunWith(SpringRunner.class)
 | 
			
		||||
@SpringBootTest
 | 
			
		||||
public class ConsumerApplicationTests {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void contextLoads() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user