springcloud 服务提供方 compute-service
------------------------------------------------------------------------------------------------------------
springcloud (零) springboot 基础 下载
springcloud (一)服务注册中心 eureka 下载
springcloud (二)服务提供方 compute-service 下载
springcloud (三)消费者 Feign(类似 websevice) 下载
springcloud (四)客户端负载均衡 ribbon 下载
springcloud (六)分布式配置中心 config server & config client 下载client 下载server
springcloud (七) bus 分布式队列 rabbitmq 下载
springcloud (八) 服务网关 gateway zuul 下载
------------------------------------------------------------------------------------------------------------
@EnableDiscoveryClient @SpringBootApplication public class SpringBootSampleApplication { public static void main(String[] args) { SpringApplication.run(SpringBootSampleApplication.class, args); } }
@RestController public class UserService { private final Logger logger = Logger.getLogger(UserService.class); @Resource UserDao userDao; @Autowired private DiscoveryClient client; @RequestMapping(value = "/user/{userId}" ,method = RequestMethod.GET) public User findById(@PathVariable(value = "userId") int userId){ ServiceInstance instance = client.getLocalServiceInstance(); logger.info("/add, host:" + instance.getHost() + ", service_id:" + instance.getServiceId() + ", result:" ); System.out.println("================productor==================="); User user = userDao.findById(userId); System.out.println("================productor==================="+user); return user; } }
package com.curiousby.cn.entity; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; /** * @Type User.java * @Desc * @author cmcc-B100036 * @date 2016年11月10日 下午3:44:08 * @version */ @Entity @Table(name = "t_user") public class User implements Serializable{ /** * */ private static final long serialVersionUID = 1381806832842693234L; @Id private int id; @Column(name = "user_name") private String userName; @Column(name = "password") private String password; @Column(name = "tel") private String tel; @Column(name = "sex") private String sex; @Column(name = "description") private String description; public int getId() { return id; } public String getUserName() { return userName; } public String getPassword() { return password; } public String getTel() { return tel; } public String getSex() { return sex; } public String getDescription() { return description; } public void setId(int id) { this.id = id; } public void setUserName(String userName) { this.userName = userName; } public void setPassword(String password) { this.password = password; } public void setTel(String tel) { this.tel = tel; } public void setSex(String sex) { this.sex = sex; } public void setDescription(String description) { this.description = description; } }
package com.curiousby.cn.dao; import javax.transaction.Transactional; import org.springframework.data.repository.CrudRepository; import com.curiousby.cn.entity.User; /** * @Type UserDao.java * @Desc * @author cmcc-B100036 * @date 2016年11月10日 下午3:49:04 * @version */ @Transactional public interface UserDao extends CrudRepository<User, Integer>{ //crud User findById(int id); }
spring.mvc.view.prefix=/WEB-INF/jsp/ spring.mvc.view.suffix=.jsp spring.application.name=compute-service server.port=1001 server.session-timeout=60 # server.address=192.168.16.11 #one datasource spring.datasource.url=jdbc:mysql://localhost:3306/database spring.datasource.username=root spring.datasource.password=root spring.datasource.driverClassName=com.mysql.jdbc.Driver eureka.client.serviceUrl.defaultZone=http://localhost:1000/eureka/
<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.curiousby.cn</groupId> <artifactId>SpringCloudDemo-Feign</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>SpringCloudDemo-Feign Maven Webapp</name> <url>http://maven.apache.org</url> <repositories> <repository> <id>spring-snapshots</id> <url>http://repo.spring.io/libs-snapshot</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>spring-snapshots</id> <url>http://repo.spring.io/libs-snapshot</url> </pluginRepository> </pluginRepositories> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.5.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.7</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-feign</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Brixton.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <finalName>SpringCloudDemo-Feign</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <useSystemClassLoader>false</useSystemClassLoader> </configuration> </plugin> </plugins> </build> </project>
捐助开发者
在兴趣的驱动下,写一个免费
的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。
谢谢您的赞助,我会做的更好!
下一篇: 广州有哪些好玩的地方 广州旅游景点排行榜
推荐阅读
-
实战SpringCloud响应式微服务系列教程(第六章)
-
springcloud学习之路: (四) springcloud集成Hystrix服务保护
-
实战SpringCloud响应式微服务系列教程(第九章)使用Spring WebFlux构建响应式RESTful服务
-
Java--IDEA创建多服务模块的SpringCloud微服务项目
-
SpringCloud教程 | 第三篇: 服务消费者(Feign)(Finchley版本)
-
SpringCloud微服务(04):Turbine组件,实现微服务集群监控
-
SpringCloud Alibaba微服务实战 - 基础环境准备
-
springcloud使用之服务的注册发现与消费
-
springcloud 微服务 分布式 Activiti6 工作流 vue.js html 跨域 前后分离
-
跟我学SpringCloud | 第三篇:服务的提供与Feign调用