当前位置: 首页 > news >正文

idea快速创建SpringCloud项目

-


IDE开发工具:IntelliJ IDEA 14.0.2


版本管理:Maven


技术栈:SpringCloud


环境:JDK 1.8


 


一、创建Maven项目
1、File——>New Project ——>Maven 如图所示:




![](https://i-blog.csdnimg.cn/blog_migrate/52d3c7746a64bfdfa13659779c234308.png)

File——>New Project



![](https://i-blog.csdnimg.cn/blog_migrate/b9c99894efcbb6628d6a257fceef9237.png)


 


2、填写模块名称和项目路径


![](https://i-blog.csdnimg.cn/blog_migrate/f476829f950e6ac9e81dcb854f2180bd.png)


![](https://i-blog.csdnimg.cn/blog_migrate/d609028f775207faed3695de3c5e4eba.png)


按照以上步骤,就简单的创建了一个Maven项目。


此时项目还不是SpringBoot项目!!


二、把maven项目变成SpringBoot项目
1、pom.xml引入需要的jar包


注意:按照各自项目实际情况;楼主是本项目由自己的maven私库


引入SpringBoot所需jar包
- 引入SpringCloud所需jar包
- 引入ereka服务注册发现客户端所需jar包
- 引入mybatis-SpringCloud依赖jar包
- 引入kafka 所需jar包
- 引入redis 所需jar包
- 引入配置中心Spring config 客户端依赖jar包

等等,按照各自项目所需。


`
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">
4.0.0

com.inks.es
msg
1.0-SNAPSHOT
jar

msg
Demo project for Spring Boot


org.springframework.boot
spring-boot-starter-parent
1.5.6.RELEASE


UTF-8
UTF-8
1.8
8.5.30




org.springframework.cloud
spring-cloud-starter-config



org.springframework.boot
spring-boot-starter-actuator


org.springframework.cloud
spring-cloud-starter-eureka



org.springframework.cloud
spring-cloud-starter-feign



org.springframework.kafka
spring-kafka



org.springframework.boot
spring-boot-starter-data-redis



org.springframework.boot
spring-boot-starter-web


org.springframework.boot
spring-boot-starter-test
test



org.mybatis.spring.boot
mybatis-spring-boot-starter
1.1.1


org.mybatis.generator
mybatis-generator-core
1.3.2


com.epaylinks.efps
common
0.0.1-SNAPSHOT


com.epaylinks.efps
logtracer
0.0.1-SNAPSHOT


org.apache.commons
commons-math
2.2


org.apache.httpcomponents
httpclient
4.5.3


org.apache.httpcomponents
httpasyncclient
4.1.1


io.github.openfeign.form
feign-form-spring
3.2.2


io.github.openfeign.form
feign-form
3.2.2





org.springframework.cloud
spring-cloud-dependencies
Dalston.SR2
pom
import






org.springframework.boot
spring-boot-maven-plugin


org.mybatis.generator
mybatis-generator-maven-plugin
1.3.2

src/main/resources/generatorConfig-mch.xml
true
true



com.oracle
ojdbc6
11.1.0.7.0


org.mybatis.generator
mybatis-generator-core
1.3.2





`
2、创建SpringCloud项目主入口类**Application


![](https://i-blog.csdnimg.cn/blog_migrate/a89d7403a57c34474ec3036ea92364c0.png)


 


`package com.s.s;

import com.ks.e.common.util.SpringContextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.kafka.annotation.EnableKafka;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.client.RestTemplate;

@RefreshScope
@EnableEurekaClient
@EnableFeignClients
@EnableKafka
@EnableScheduling
@EnableAspectJAutoProxy(proxyTargetClass=true , exposeProxy=true)
@SpringBootApplication
public class MsgApplication {
// 启动的时候要注意,由于我们在controller中注入了RestTemplate,所以启动的时候需要实例化该类的一个实例
@Autowired
private RestTemplateBuilder builder;

// 使用RestTemplateBuilder来实例化RestTemplate对象,spring默认已经注入了RestTemplateBuilder实例
@Bean
public RestTemplate restTemplate() {
return builder.build();
}

public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(MsgApplication.class);
SpringContextUtils.setApplicationContext(springApplication.run(args));
}
}`
@SpringBootApplication  这个标注就表示,这个项目是SpringBoot项目,并且此类是项目的主入口类。


由以下main方法启动Application


` public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(MsgApplication.class);
SpringContextUtils.setApplicationContext(springApplication.run(args));
}`
到这里,SpringBoot项目已经完成一大半。接下来就是数据库连接配置以及注册中心config和Ereka等配置文件的配置了


三、注册中心和服务发现配置等
1、Spring Config Center配置项目的配置文件读取


楼主这里是以Spring Config Center作为配置中心来,配置读取项目所需的各种连接和配置信息等(Spring Config Center这里不作详细介绍)


2、GitLab远程托管配置信息


在Spring Config Center配置服务中心配置好了项目的连接和读取权限后,在gitlab上配置本项目的各种所需信息


这里详见另一篇文章


SpringCloud项目采用gitLab作为配置中心


3、项目中加载各环境下对应的配置文件信息(dev、test、prod、uat)


这里以dev开发环境为例




![](https://i-blog.csdnimg.cn/blog_migrate/85392f1f0e63bbf83586150bdbaf834d.png)

按照图标顺序依次加载



 


所有SpringCloud项目均是从bootstrap.yml文件开始加载项目所需的各种连接和配置信息的,这是SpringCloud核心内置决定,可以去研究源码,这里不作详述。


4、bootstrap-dev.yml的配置如:


`spring:
application:
name: msg
cloud:
config:
uri: http://172.20.4.80:9000/ # 配置spring cloud config服务端的url
profile: dev # 指定profile
label: master # 指定gitlab仓库的分支`
主要是连接spring cloud config服务端,以获取远程gitlab上的配置信息。


5、application-dev.yml的配置如下:


`eureka:
client:
registerWithEureka: true
service-url:
defaultZone: http://172.20.4.80:8000/eureka/
swagger:
enable: true`
主要用来连接eureka服务注册和发现


到这里,SpringCLoud项目基本已经完成。接下来就是各种数据库建表Mybatis配置和撸代码的工作了。


![](https://i-blog.csdnimg.cn/blog_migrate/0ca7e0e4b62071922e78a89e8a7bfcbd.png)


![](https://i-blog.csdnimg.cn/blog_migrate/84975873a04a54beda948c66c25a0fee.png)


 


 




![](https://i-blog.csdnimg.cn/blog_migrate/073c53da3d97d2be8dbf3fb4bfde91fd.jpeg)

同名原创公众号:
程序大视界

http://www.jsqmd.com/news/922411/

相关文章:

  • EldenRingSaveCopier:拯救你的《艾尔登法环》游戏进度的终极指南
  • VUE跨页面传值的精妙
  • 网络技术12-FTP协议详解——传统文件传输的“老派方案“
  • FUXA管道动画制作:从静态流程图到动态工业监控的转变
  • Windows 11安装绕过工具终极指南:让老旧电脑也能流畅升级
  • 抽象之美——万物皆可设计
  • 济南倍乐管家:莱芜专业的深度清洁软装地毯公司选哪家 - LYL仔仔
  • MTK刷机工具终极指南:3步解锁联发科设备救砖与系统修复
  • 2026年宜昌市CPPM报名十大核心问题全流程答疑 - 众智商学院课程中心
  • 别再死记硬背公式了!用Python+PyTorch图解马尔可夫随机场(MRF)在图像去噪中的应用
  • 【Python系列课程】NumPy数组计算(下):向量化运算、广播机制与聚合函数
  • 2026西安曲江家政服务行业观察:唐僧到家等机构如何引领行业规范化发展 - 资讯快报
  • Beyond Compare 5密钥生成器:深度解析Python逆向工程实现方案
  • AI写专著高效之道:借助AI工具,3天完成20万字专著创作!
  • 2026年苏州区域专业防水补漏3家本土合规服务企业全方位分析与场景适配解读 专业防水公司排名推荐(2026年5月防水补漏最新TOP权威排名) - 鼎壹万修缮说
  • 7步精通思源宋体TTF:开源中文字体终极解决方案
  • Redis安装部署
  • 源码分析【三】ArrayList与LinkedList的比较
  • TVA在传统安防迈向智能物联(AIoT)中的突破与应用(2)
  • LibreDWG完全指南:5个关键优势解决DWG文件处理难题
  • XUnity.AutoTranslator:打破语言壁垒的Unity游戏翻译神器终极指南
  • 老显卡(GTX750/1050)也能玩转AI绘画?手把手教你升级驱动装CUDA11.4
  • 告别低效写作:盘点2026年实力封神的的降AI率平台 - 降AI小能手
  • idea中Maven基本介绍
  • 2026零添加蜂蜜水推荐:彭祖蜜分离式蜂蜜水值得选吗 - 资讯快报
  • 2026年4月市场正规的街舞文化推广基地推荐,开启创意之旅,着力推广街舞天地 - 品牌推荐师
  • 《中间件》——kafka的工作原理解析
  • 2026版机房动环智慧联动管控整体解决方案
  • 3分钟快速解密QQ音乐:qmcdump让你的加密音乐重获自由播放
  • JDK1.8的几个简单Lambda表达式