微服务架构下如何集成支付宝接口实现支付服务(三)结合配置中心搭建eureka服务注册中心

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_42237752/article/details/96479439

本项目中其他模块内容:
微服务架构下如何集成支付宝接口实现支付服务(一)总体设计.
微服务架构下如何集成支付宝接口实现支付服务(二)使用SpringCloudConfig搭建配置中心.
微服务架构下如何集成支付宝接口实现支付服务(三)结合配置中心搭建eureka服务注册中心.
微服务架构下如何集成支付宝接口实现支付服务(四)集成alipay来提供支付服务.
微服务架构下如何集成支付宝接口实现支付服务(五)消费支付服务的消费者搭建.
微服务架构下如何集成支付宝接口实现支付服务(六)支付宝接口(沙箱环境)申请.

1、pom文件

<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.shqblog</groupId>
    <artifactId>blog</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>blog-eureka-6731</artifactId>
  <dependencies>
    <!-- config配置中心依赖 -->
 	<dependency>
		<groupId>org.springframework.cloud</groupId>
		<artifactId>spring-cloud-starter-config</artifactId>
	</dependency>
	<!-- eureka的服务器端依赖 -->
  	<dependency>
  		<groupId>org.springframework.cloud</groupId>
  		<artifactId>spring-cloud-starter-eureka-server</artifactId>
  		<version>1.4.3.RELEASE</version>
  	</dependency>
  		<!-- 热部署 -->
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-devtools</artifactId>
	</dependency>
  </dependencies>  
</project>

2、文件目录结构

整个目录结构非常简单,主要就是配置文件和启动类
在这里插入图片描述

3、配置文件

配置文件这里提一下,这里的bootstrap.yml是系统级配置文件,是最先进行加载的,如果加载失败,再去找application.yml文件加载配置

所以bootstrap.yml文件内容:这里是加载的配置中心的配置项,如果不会使用SpringCloudConfig的同学可以看这篇微博:使用SpringCloudConfig搭建配置中心

spring:
  cloud:
    config:
      name: blog-config-eureka #需要从github上读取的资源名称,注意没有yml后缀名
      profile: dev    # 本次访问的配置项
      label: master
      uri: http://localhost:3344 #这个是搭建的SpringCloudConfig配置中的地址

而application.yml中的内容其实应该从配置中心中获取,当然也可以不使用配置中心,直接再本地配置,

erver: 
  port: 6731
spring:
  profiles: dev #如果是本地配置请将这行注释掉
eureka:
  instance:
    hostname: localhost   # eureka服务端的实例名称
  client:
    register-with-eureka: false  # false表示不向注册中心注册自己
    fetch-registry: false  #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
    service-url: 
     defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/    #设置eureka server交互的地址查询服务和注册服务都需要依赖这个地址
     #defaultZone:http://eureka7002.com:7002/eureka,http://eureka7003.com:7003/eureka
     #如果需要使用eureka的集群配置则将上面这条注释解开,内容是配置其他eureka服务器的地址。

4、启动器配置

这里启动器配置只需要打开eureka的配置

@SpringBootApplication
@EnableEurekaServer  //打开eureka配置项
public class Eureka_6731_StartSpringCloudApp {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SpringApplication.run(Eureka_6731_StartSpringCloudApp.class, args);
	}

}

接下来即可将项目运行起来,

5、测试

在浏览器中输入

http://localhost:6731/

显示如下内容说明配置成功。

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42237752/article/details/96479439