入行7年,从Delphi到Java,再到前端,全栈,一路走来,磕磕碰碰。回顾一下过去,总结经验,继续学习、前进。
以一个全栈工程师的角度,记录下如何在一个传统公司或中小型公司独立快速开发系统,独当一面,包括前端、后端、数据库、小程序等,遇到的问难和解决方案也会分享在此,希望对有需要的朋友有所帮助(大佬们无视~)!
该系列文章适合有一定Java基础和SpringBoot开发经验的人。另外由于是以一个比较完整的项目作为例子,所以许多搭建细节不作描述。
开发环境:Idea2020、JDK11(Idea2017、JDK8也可以)
技术栈:SpringBoot、Alibaba Cloud、Nacos、Redis、Vue、ElementUI
数据库:PostgreSQL10
开始吧!
项目创建
一、创建Maven项目
1.pom文件中配置版本信息和依赖(是最顶层模块的pom)
pom
1.0.0
business-center
common-center
api-gateway
11
11
11
2.3.3.RELEASE
Hoxton.SR8
2.2.1.RELEASE
3.4.0
1.18.16
3.9
1.15
3.0.0
true
org.springframework.boot
spring-boot-dependencies
${spring.boot.version}
pom
import
org.springframework.cloud
spring-cloud-dependencies
${spring.cloud.version}
pom
import
com.alibaba.cloud
spring-cloud-alibaba-dependencies
${alibaba.cloud.version}
pom
import
com.baomidou
mybatis-plus-boot-starter
${mybatisplus.boot.starter.version}
org.projectlombok
lombok
${lombok.version}
org.apache.commons
commons-lang3
${commons.lang3.version}
io.springfox
springfox-boot-starter
${springfox.boot.starter.version}
com.aliyun.oss
aliyun-sdk-oss
3.10.2
io.jsonwebtoken
jjwt
0.7.0
com.baomidou
kaptcha-spring-boot-starter
1.1.0
commons-codec
commons-codec
${commons.codec.version}
maven-ali
http://maven.aliyun.com/nexus/content/groups/public//
true
true
always
fail
public
aliyun nexus
http://maven.aliyun.com/nexus/content/groups/public/
true
false
${artifactId}
org.springframework.boot
spring-boot-maven-plugin
${spring.boot.version}
true
true
org.apache.maven.plugins
maven-compiler-plugin
3.8.1
11
11
2.common-center配置
11 11 org.springframework.boot spring-boot-starter-weborg.springframework.boot spring-boot-starter-testorg.projectlombok lombokcom.baomidou mybatis-plus-boot-startermysql mysql-connector-javaorg.postgresql postgresqlcom.baomidou mybatis-plus-generator3.4.1 org.apache.velocity velocity-engine-core2.0 io.springfox springfox-boot-starterorg.springframework.boot spring-boot-starter-data-redisio.lettuce lettuce-coreredis.clients jediscom.fasterxml.jackson.core jackson-annotations2.12.2 org.apache.commons commons-lang3commons-collections commons-collections3.2.2 com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discoverycom.alibaba.cloud spring-cloud-starter-alibaba-nacos-configorg.springframework.cloud spring-cloud-starter-openfeigncom.alibaba fastjson1.2.58 commons-codec commons-codecio.jsonwebtoken jjwtorg.springframework.boot spring-boot-starter-mail
3.api-gateway配置
11 11 org.springframework.cloud spring-cloud-starter-gatewaycom.alibaba.cloud spring-cloud-starter-alibaba-nacos-discoverycom.alibaba.cloud spring-cloud-starter-alibaba-nacos-config
4.business-center业务中心,创建一些业务服务模块,这里以user-center用户服务为例
business-center
业务中心
user-center
pom
11
11
5.user-center用户服务
net.work common-center1.0.0 com.baomidou kaptcha-spring-boot-startercom.aliyun.oss aliyun-sdk-oss
二、创建基础的包和启动类
1.依赖包都下载好后,将基础的包和启动类创建出来
package net.work;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication
@EnableDiscoveryClient
@MapperScan("net.work.mapper")
@EnableTransactionManagement
public class UserCenterApp {
public static void main(String[] args) {
SpringApplication.run(UserCenterApp.class, args);
}
}
package net.work;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication
@EnableDiscoveryClient
public class GatewayServerApp {
public static void main(String[] args) {
SpringApplication.run(GatewayServerApp.class, args);
}
}
2.配置文件
application.yml不需要写任何内容,基本上没有特殊配置,bootstrap.yml中的配置都大同小异
(1)网关服务
spring:
application:
name: api-gateway-service
cloud:
nacos:
config:
server-addr: localhost:8848 #Nacos配置中心地址(本地)
file-extension: yaml #文件拓展格式
# profiles:
# active: dev #本地开发环境
# active: pro #线上生产环境
(2)用户服务
spring:
application:
name: user-service
cloud:
nacos:
config:
server-addr: localhost:8848 #Nacos配置中心地址(本地)
file-extension: yaml #文件拓展格式
# profiles:
# active: dev #本地开发环境
# active: pro #线上生产环境
下一次,整合Nacos,让项目跑起来!



