天天看点

SpringCloud 服务提供者

SpringCloud 服务提供者

个人博客网:www.lfuping.cn    (你想要的这里多有)

SpringCloud 服务提供者

这个没啥好说的代码也就那个几句,直接看运行效果。

用到MySQL的数据库很简单就一个测试表:

/*
Navicat MySQL Data Transfer
Source Server         : 47.107.50.15
Source Server Version : 50630
Source Host           : 47.107.50.15:3306
Source Database       : springcloudDB
Target Server Type    : MYSQL
Target Server Version : 50630
File Encoding         : 65001
Date: 2018-11-26 16:09:26
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `t_student`
-- ----------------------------
DROP TABLE IF EXISTS `t_student`;
CREATE TABLE `t_student` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(20) NOT NULL,
  `grade` varchar(20) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of t_student
-- ----------------------------
INSERT INTO `t_student` VALUES ('1', '小明', '三');
           

就一个用spring JPA做的简单的查询

SpringCloud 服务提供者

配置如下:

server:
  port: 1001
  context-path: /
# 数据源配置
spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://47.107.50.15:3306/springcloudDB
    username: root
    password: lifuping0.
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
eureka:
  instance:
    hostname: localhost  #eureka客户端主机实例名称
    appname: springcloud-provider  #客户端服务名
    instance-id: springcloud-provider:1 #客户端实例名称
    prefer-ip-address: true #显示IP
  client: 
    service-url: 
      defaultZone: http://localhost:7001/eureka   #把服务注册到eureka注册中心
           

暴露服务到eureka服务注册中心

SpringCloud 服务提供者
源码下载链接: https://pan.baidu.com/s/1Lhnv4cuCWUDyB3vnpXSwCg 
提取码: bhh4
           
SpringCloud 服务提供者

                                                     欢迎关注我的微信公众号:平川大叔

继续阅读