(八)整合spring cloud云服务架构 - commonservice-eureka 项目构建过程

简介: java、spring cloud、spring boot

我们针对于HongHu cloud的eureka项目做以下构建,整个构建的过程很简单,我会将每一步都构建过程记录下来,希望可以帮助到大家:

  1. 创建一个名为particle-common-eureka的maven项目,继承particle-commonservice,具体的pom.xml配置文件如下:

Xml代码 收藏代码
<?xml version="1.0" encoding="UTF-8"?>

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.ml.honghu</groupId>  
    <artifactId>particle-commonservice</artifactId>  
    <version>0.0.1-SNAPSHOT</version>  
</parent>  

<artifactId>particle-commonservice-eureka</artifactId>  
<packaging>jar</packaging>  

<name>particle-commonservice-eureka</name>  
<description>particle-commonservice project for Spring Boot</description>  

<dependencies>  
    <dependency>  
        <groupId>org.springframework.cloud</groupId>  
        <artifactId>spring-cloud-starter-eureka-server</artifactId>  
    </dependency>  
    <dependency>  
        <groupId>org.springframework.boot</groupId>  
        <artifactId>spring-boot-starter-security</artifactId>  
    </dependency>  
    <dependency>  
        <groupId>org.springframework.boot</groupId>  
        <artifactId>spring-boot-devtools</artifactId>  
    </dependency>  
      
    <dependency>  
        <groupId>org.springframework.boot</groupId>  
        <artifactId>spring-boot-starter-test</artifactId>  
        <scope>test</scope>  
    </dependency>  

</dependencies>  

<build>  
    <plugins>  
        <plugin>  
            <groupId>org.springframework.boot</groupId>  
            <artifactId>spring-boot-maven-plugin</artifactId>  
            <executions>  
                <execution>  
                    <id>1</id>  
                    <goals>  
                        <goal>repackage</goal>  
                    </goals>  
                </execution>  
                <execution>  
                    <id>2</id>  
                    <goals>  
                        <goal>build-info</goal>  
                    </goals>  
                </execution>  
            </executions>  
            <configuration>  
                <executable>true</executable>  
            </configuration>  
              
        </plugin>  
    </plugins>  
</build>  

  1. 在启动类入口引用eureka的相关配置,代码如下:

Java代码 收藏代码
package com.ml.honghu;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@EnableEurekaServer
@SpringBootApplication
public class ServiceApplication {

public static void main(String[] args) {  
    SpringApplication.run(ServiceApplication.class, args);  
}  

}

  1. 配置application.yml文件

Xml代码 收藏代码

server (eureka 默认端口为:8761)

server:
port: 8761

spring

spring:
application:

name: particle-commonservice-erueka  

eureka

eureka:
client:

# 是否注册到eureka  
register-with-eureka: true  
# 是否从eureka获取注册信息  
fetch-registry: false  
availability-zones:   
  honghu: honghuZone  
service-url:   
  honghuZone: http://honghu:123456@localhost:8761/eureka/  
  defaultZone: http://honghu:123456@localhost:8761/eureka/  

instance:

prefer-ip-address: true  
hostname: localhost  
metadataMap:  
  zone: honghuZone  
  user: ${security.user.name}  
  password: {security.user.password}  
    

# 指定环境
environment: dev
#指定数据中心
datacenter: honghu
# 关闭自我保护模式
server:

enable-self-preservation: false  

#设置清理无效节点的时间间隔,默认60000,即是60s

eviction-interval-timer-in-ms: 60000  

服务认证

security:
basic:

enabled: true  

user:

name: honghu  
password: 123456  

management:
security:

enabled: false  
  1. 增加项目的log机制和打包运行机制(后面我们会详细编写针对于Linux Centos下的打包部署机制)
  2. 自此整个项目部署完成,通过手动方式进行Run As --> Spring Boot App,运行结果如下:

控制台运行结果:

访问控制台并登陆:

控制台运行效果:

从现在开始,我这边会将近期研发的spring cloud微服务云架构的搭建过程和精髓记录下来,帮助更多有兴趣研发spring cloud框架的朋友,大家来一起探讨spring cloud架构的搭建过程及如何运用于企业项目。
(企业架构源码可以加求球:叁五三陆二肆柒二伍玖)

目录
相关文章
|
14天前
|
人工智能 JavaScript 安全
【01】Java+若依+vue.js技术栈实现钱包积分管理系统项目-商业级电玩城积分系统商业项目实战-需求改为思维导图-设计数据库-确定基础架构和设计-优雅草卓伊凡商业项目实战
【01】Java+若依+vue.js技术栈实现钱包积分管理系统项目-商业级电玩城积分系统商业项目实战-需求改为思维导图-设计数据库-确定基础架构和设计-优雅草卓伊凡商业项目实战
58 13
【01】Java+若依+vue.js技术栈实现钱包积分管理系统项目-商业级电玩城积分系统商业项目实战-需求改为思维导图-设计数据库-确定基础架构和设计-优雅草卓伊凡商业项目实战
|
2月前
|
Java 开发者 微服务
从单体到微服务:如何借助 Spring Cloud 实现架构转型
**Spring Cloud** 是一套基于 Spring 框架的**微服务架构解决方案**,它提供了一系列的工具和组件,帮助开发者快速构建分布式系统,尤其是微服务架构。
305 69
从单体到微服务:如何借助 Spring Cloud 实现架构转型
|
19天前
|
存储 NoSQL Java
使用Java和Spring Data构建数据访问层
本文介绍了如何使用 Java 和 Spring Data 构建数据访问层的完整过程。通过创建实体类、存储库接口、服务类和控制器类,实现了对数据库的基本操作。这种方法不仅简化了数据访问层的开发,还提高了代码的可维护性和可读性。通过合理使用 Spring Data 提供的功能,可以大幅提升开发效率。
62 21
|
9天前
|
网络协议 Java Shell
java spring 项目若依框架启动失败,启动不了服务提示端口8080占用escription: Web server failed to start. Port 8080 was already in use. Action: Identify and stop the process that’s listening on port 8080 or configure this application to listen on another port-优雅草卓伊凡解决方案
java spring 项目若依框架启动失败,启动不了服务提示端口8080占用escription: Web server failed to start. Port 8080 was already in use. Action: Identify and stop the process that’s listening on port 8080 or configure this application to listen on another port-优雅草卓伊凡解决方案
41 7
|
22天前
|
XML Java 开发者
Spring底层架构核心概念解析
理解 Spring 框架的核心概念对于开发和维护 Spring 应用程序至关重要。IOC 和 AOP 是其两个关键特性,通过依赖注入和面向切面编程实现了高效的模块化和松耦合设计。Spring 容器管理着 Beans 的生命周期和配置,而核心模块为各种应用场景提供了丰富的功能支持。通过全面掌握这些核心概念,开发者可以更加高效地利用 Spring 框架开发企业级应用。
74 18
|
1月前
|
开发框架 前端开发 .NET
一个适用于 .NET 的开源整洁架构项目模板
一个适用于 .NET 的开源整洁架构项目模板
58 26
|
1月前
|
搜索推荐 NoSQL Java
微服务架构设计与实践:用Spring Cloud实现抖音的推荐系统
本文基于Spring Cloud实现了一个简化的抖音推荐系统,涵盖用户行为管理、视频资源管理、个性化推荐和实时数据处理四大核心功能。通过Eureka进行服务注册与发现,使用Feign实现服务间调用,并借助Redis缓存用户画像,Kafka传递用户行为数据。文章详细介绍了项目搭建、服务创建及配置过程,包括用户服务、视频服务、推荐服务和数据处理服务的开发步骤。最后,通过业务测试验证了系统的功能,并引入Resilience4j实现服务降级,确保系统在部分服务故障时仍能正常运行。此示例旨在帮助读者理解微服务架构的设计思路与实践方法。
105 17
|
2月前
|
存储 JSON 前端开发
【Spring项目】表白墙,留言板项目的实现
本文主要介绍了表白墙项目的实现,包含前端和后端代码,以及测试
|
2月前
|
JSON 前端开发 Java
|
2月前
|
缓存 前端开发 Java
【Spring】——SpringBoot项目创建
SpringBoot项目创建,SpringBootApplication启动类,target文件,web服务器,tomcat,访问服务器

热门文章

最新文章