微服务springboot搭建记账网站-第三方数据服务

  1. 一般是由第三方提供,数据放在压缩包里面,是json格式,这里简单的自己新加几个账户数据
  2. 接着继续创建子模块third-part-index-data-project,然后修改pom文件,增加web服务,增加eureka-client用于在注册中心作为微服务
<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>cn.cashbook.trend</groupId>
    <artifactId>trendParentProject</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>third-part-index-data-project</artifactId>
  <name>third-part-index-data-project</name>
  <description>third-part-index-data-project</description>
  <dependencies>
    <!--spring mvc-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!-- eureka-client -->
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
  </dependencies>
</project>
  1. 然后增加一个ThirdPartIndexDataApplication启动类
**package cn.cashbook.trend;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.NetUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@SpringBootApplication
@EnableEurekaClient
public class ThirdPartIndexDataApplication {
    public static void main(String[] args) {
        int port = 8090;
        int eurekaServerPort = 8761;

        if(NetUtil.isUsableLocalPort(eurekaServerPort)) {
            System.err.printf("检查到%端口没有打开,eureka无法启动%n",eurekaServerPort);
            System.exit(1);
        }
        if(null != args && 0 != args.length) {
            for(String arg : args) {
                if(arg.startsWith("port=")) {
                    String strPort = StrUtil.subAfter(arg,"port=",true);
                    if(NumberUtil.isNumber(strPort)) {
                        port = Convert.toInt(strPort);
                    }
                }
            }
        }
        if(!NetUtil.isUsableLocalPort(port)) {
            System.err.printf("端口%d被占用了,无法启动%n", port );
            System.exit(1);
        }
        new SpringApplicationBuilder(ThirdPartIndexDataApplication.class).properties("server.port=" + port ).run(args);

    }
}
**
  1. 增加个 application.yml.,说明注册中心的位置
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
spring:
  application:
    name: third-part-index-data-project

  1. 增加一些记账的数据,现在可以手动增加
    注意数据要保存在resources下面 在http://127.0.0.1:8090/indexes/codes.json访问
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值