SpringCloud开发个人博客项目(框架搭建)
1. SpringCloud简介
我们先看看springCloud官网(https://spring.io/projects/spring-cloud#overview)上的介绍:
Spring Cloud provides tools for developers to quickly build some of the common patterns in distributed systems (e.g. configuration management, service discovery, circuit breakers, intelligent routing, micro-proxy, control bus, one-time tokens, global locks, leadership election, distributed sessions, cluster state). Coordination of distributed systems leads to boiler plate patterns, and using Spring Cloud developers can quickly stand up services and applications that implement those patterns. They will work well in any distributed environment, including the developer’s own laptop, bare metal data centres, and managed platforms such as Cloud Foundry.
大概意思就是SpringCloud为开发者提供了构建分布式系统的基础工具,也就是说让你自己实现一个分布式系统是很难的,也很耗时间的,所以SpringCloud这个东东给我们提供了快速构建这种模式的工具。
相信开发人员都有体会,SpringCloud现在是非常流行的一个分布式微服务框架,而且现在好多公司也采用了这个框架做自己的微服务,有的公司已经实用这个框架对自己原有的项目做了系统重构。
在这次的个人博客项目中,遇到比较难懂的组件,我会从源码进行分析,每一步遇到的比较有难度的bug,会写出解决的具体方案。项目的所有源码都会上传到全球最大的同性交友平台GitHub上,如果有需要的小伙伴可以clone到自己的本地仓库。现在我们就是用SpringCloud来开发一个自己的个人博客项目,下面进入主题。
2. 项目架构
个人博客项目,我这里使用的组件全部是SpringCloud的,对于有些组件在使用过程中遇到的版本兼容问题,遇到我们解决,下面给出项目的架构图如下图:
上面图片给出了项目的整体架构图,当然现在的架构不是最终的,在实际开发过程中,我们慢慢迭代出一个好的架构出来,所谓:好的架构都是一步一步迭代出来的。
3. 项目搭建
下面开始项目的实际搭建工作,开发环境使用idea,使用eclipse的小伙伴,我这里强烈建议换到idea的队伍中。废话不多说,我们开始项目的搭建工作。
3.1 根项目搭建
在idea中新建项目,搭建项目的root,如下图。
这里下一步下一步就可以了,注意命名规则就行,这个如果不懂自己网上找资料,这方面的文章现在网上很多,创建完项目之后,如下图,对自己的项目做一个简单的整理。
删除上面红色标注的文件,然后打开pom文件,这里需要对pom文件做一些修改,如下图:
pom文件里面添加如下代码:
<packaging>pom</packaging>
关于maven的知识,如果不了解的可以私下自己补充一下这方面的知识,这里就不详细赘述了。
3.2 注册中心创建
在3.1创建的根文件上,右键创建module项目,如下图:
然后和3.1步骤一样,下一步到项目依赖的页,我们对注册中心依赖进行添加,如下图:
点击下一步完成注册中心的创建,注册中心创建之后,我这里将pom文件里面springBoot的版本做了修改,代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.blog</groupId>
<artifactId>register</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>register</name>
<description>注册中心</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Edgware.SR2</spring-cloud.version>
</propertie
鑫动了~: uniapp 中如和修改呢
A默苍离: parmMap.put("code2", code + "/%/%"); 这种是什么意思?
「已注销」: //hour为当前时间的小时数,根据当前时间来计算时间戳 public void getTime(int hour) { //int hour = 17; long time = new Date().getTime(); for(int i=0; i<hour; i++) { time = time-3600; System.out.println(i+"小时 "+time); } for(int i=17; i<hour; i++) { time = time+3600; System.out.println(i+"小时 "+time); } }
郭瑞轩: 牛逼 就是这种写法
暮辰780: 可以直接放到index.html头部吗