(八)整合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架构的搭建过程及如何运用于企业项目。
(企业架构源码可以加求球:叁五三陆二肆柒二伍玖)

目录
相关文章
|
2天前
|
监控 安全 Java
Spring cloud原理详解
Spring cloud原理详解
13 0
|
6天前
|
XML Java 数据格式
Spring 项目如何使用AOP
Spring 项目如何使用AOP
19 2
|
6天前
|
Java Spring
Spring boot项目如何发送邮件
Spring boot项目如何发送邮件
16 2
|
6天前
|
消息中间件 负载均衡 Java
【Spring Cloud 初探幽】
【Spring Cloud 初探幽】
14 1
|
8天前
|
Java 开发者 微服务
Spring Cloud原理详解
【5月更文挑战第4天】Spring Cloud是Spring生态系统中的微服务框架,包含配置管理、服务发现、断路器、API网关等工具,简化分布式系统开发。核心组件如Eureka(服务发现)、Config Server(配置中心)、Ribbon(负载均衡)、Hystrix(断路器)、Zuul(API网关)等。本文讨论了Spring Cloud的基本概念、核心组件、常见问题及解决策略,并提供代码示例,帮助开发者更好地理解和实践微服务架构。此外,还涵盖了服务通信方式、安全性、性能优化、自动化部署、服务网格和无服务器架构的融合等话题,揭示了微服务架构的未来趋势。
32 6
|
12天前
|
JSON Java Apache
Spring Cloud Feign 使用Apache的HTTP Client替换Feign原生httpclient
Spring Cloud Feign 使用Apache的HTTP Client替换Feign原生httpclient
|
12天前
|
Java API 数据安全/隐私保护
【亮剑】如何在Java项目中结合Spring框架实现邮件发送功能
【4月更文挑战第30天】本文介绍了如何在Java项目中结合Spring框架实现邮件发送功能。首先,需在`pom.xml`添加Spring和JavaMail依赖。然后,在`applicationContext.xml`配置邮件发送器,包括SMTP服务器信息。接着,创建一个使用依赖注入的`EmailService`类,通过`JavaMailSender`发送邮件。最后,调用`EmailService`的`sendSimpleEmail`方法即可发送邮件。最佳实践包括:使用配置管理敏感信息,利用`MimeMessage`构造复杂邮件,异常处理和日志记录,以及在大量发送时考虑使用邮件队列。
|
12天前
|
负载均衡 Java 开发者
Spring Cloud:一文读懂其原理与架构
Spring Cloud 是一套微服务解决方案,它整合了Netflix公司的多个开源框架,简化了分布式系统开发。Spring Cloud 提供了服务注册与发现、配置中心、消息总线、负载均衡、熔断机制等工具,让开发者可以快速地构建一些常见的微服务架构。
|
3天前
|
存储 监控 API
构建高效微服务架构:后端开发的现代实践
【5月更文挑战第9天】 在本文中,我们将深入探讨如何在后端开发中构建一个高效的微服务架构。通过分析不同的设计模式和最佳实践,我们将展示如何提升系统的可扩展性、弹性和维护性。我们还将讨论微服务架构在处理复杂业务逻辑和高并发场景下的优势。最后,我们将分享一些实用的工具和技术,以帮助开发者实现这一目标。