[置顶] idea创建springcloud项目图文教程(创建消费者)(八)
2017-09-05 20:35
585 查看
前期条件,已经创建好注册中心,如果没有,请看上一篇http://blog.csdn.net/hcmony/article/details/77855158。
一,创建服务提供者
springcloud项目创建参考http://blog.csdn.net/hcmony/article/details/77855158
1,pox.xml
2,application.properties
3,SpringcloudCustomerApplication
4,TestController
5,TestService
idea创建maven项目,本教程适合各类小白(一)
idea创建maven,spring,springmvc,mybatis,项目(二)
idea创建maven,spring,springmvc,mybatis,项目(三)
idea创建springboot项目图文教程(四)
idea创建springboot项目图文教程(配置文件)(五)
idea创建springcloud项目图文教程(EurekaServer注册中心)(六)
idea创建springcloud项目图文教程(创建服务提供者)(七)
idea创建springcloud项目图文教程(创建消费者)(八)
idea创建springcloud项目图文教程(Feign实现负载均衡)(九)
一,创建服务提供者
springcloud项目创建参考http://blog.csdn.net/hcmony/article/details/77855158
1,pox.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.hcmony</groupId> <artifactId>springcloud-customer</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>springcloud-customer</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifact 4000 Id> <version>1.5.6.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> <spring-cloud.version>Dalston.SR3</spring-cloud.version> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-feign</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</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>${spring-cloud.version}</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> </project>
2,application.properties
eureka.client.service-url.defaultZone: http://localhost:8761/eureka/ server.port=8764 spring.application.name=springcloud-customer
3,SpringcloudCustomerApplication
package com.hcmony; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.feign.EnableFeignClients; @EnableFeignClients @EnableDiscoveryClient @SpringBootApplication public class SpringcloudCustomerApplication { public static void main(String[] args) { SpringApplication.run(SpringcloudCustomerApplication.class, args); } }
4,TestController
package com.hcmony; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; /** * Created by hcmony on 2017/9/5. */ @RestController public class TestController { @Autowired private TestService testService; @RequestMapping(value = "/test",method = RequestMethod.GET) public String test(){ return testService.test(); } }
5,TestService
package com.hcmony; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.web.bind.annotation.RequestMapping; /** * Created by hcmony on 2017/9/5. */ @FeignClient(value = "springcloud-server") public interface TestService { @RequestMapping("/test") public String test(); }
idea创建maven项目,本教程适合各类小白(一)
idea创建maven,spring,springmvc,mybatis,项目(二)
idea创建maven,spring,springmvc,mybatis,项目(三)
idea创建springboot项目图文教程(四)
idea创建springboot项目图文教程(配置文件)(五)
idea创建springcloud项目图文教程(EurekaServer注册中心)(六)
idea创建springcloud项目图文教程(创建服务提供者)(七)
idea创建springcloud项目图文教程(创建消费者)(八)
idea创建springcloud项目图文教程(Feign实现负载均衡)(九)
相关文章推荐
- [置顶] idea创建springcloud项目图文教程(Feign实现负载均衡)(九)
- idea创建springcloud项目图文教程(创建消费者)(八)
- [置顶] idea创建springcloud项目图文教程(创建服务提供者)(七)
- [置顶] idea创建springcloud项目图文教程(EurekaServer注册中心)(六)
- [置顶] idea创建springcloud项目图文教程(Feign实现负载均衡)(九)
- [置顶] idea创建springboot项目图文教程(配置文件)(五)
- idea创建springcloud项目图文教程(创建服务提供者)(七)
- [置顶] idea创建springboot项目图文教程(四)
- idea创建springcloud项目图文教程(EurekaServer注册中心)(六)
- 使用IDEA创建Java Web项目并部署访问的图文教程
- idea创建springboot项目图文教程(配置文件)(五)
- idea创建springboot项目图文教程(四)
- [置顶] idea创建maven项目,本教程适合各类小白(一)
- IntelliJ IDEA 12 创建Web项目图文详细教程(转)
- IntelliJ IDEA创建maven多模块项目(图文教程)
- 安装idea带破解和创建第一个Maven项目图文详解
- 【SpringMVC-003】idea创建SpringMVC项目傻瓜教程-URL传值
- idea 创建 java web项目(图文)
- idea创建普通的java小项目教程
- 用Eclipse 创建一个简单的web项目(图文教程)