application.yml配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#指定服务的端口
server:
port: #端口号

#公共配置
mybatis:
configuration:
#禁用缓存
cache-enabled: false
#配置映射驼峰命名法
map-underscore-to-camel-case: true
#将运行的sql语句在控制台输出
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

#配置knife4j
knife4j:
enable: true #开启增强配置
production: false #生产环境屏蔽,开启将禁止访问在线API文档
#Basic认证功能,既是否需要通过用户名, 密码验证后才能访问在线API文档

basic:
enable: false #是否开启Basic认证
#如果开启Basic认证,但是没有配置用户名和密码, 默认是admin/123321
username: root
password: root

#指定服务的应用名称(service-id)
spring:
application:
name: #应用名称
profiles:
active: dev #将来会激活dev的profile文件

XML依赖

web实例

1
2
3
4
5
<!--web实例-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

mybatis整合springboot

1
2
3
4
5
 <!--mybatis整合springboot-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>

mysql驱动

1
2
3
4
5
<!--mysql驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>

在线api文档

1
2
3
4
5
<!--在线api文档-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
</dependency>

alibaba 数据源德鲁伊

1
2
3
4
5
<!--alibaba 数据源德鲁伊-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>

application-dev.yml配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
spring:
#配置数据库连接
datasource:
url: jdbc:mysql://localhost:3306/csmall_db?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimeZone=Asia/Shanghai&allowMultiQueries=true
username: root
password: root
#配置nacos信息
cloud:
nacos:
discovery:
server-addr: localhost:8848
#配置sentinel信息
sentinel:
transport:
dashboard: localhost:8080 #配置sentinel仪表盘的位置
port: 8721 #执行限流的端口,每个项目是唯一的,如果此项目使用了8721端口,其余就不能使用该端口了

#配置dubbo信息
dubbo:
protocol:
#port设置成-1是Dubbo框架支持的特殊写法,会自动动态生成可用的端口,规则是从20880开始,
#如果被占用就递增使用
port: -1
#设置连接的名称,一般固定就叫dubbo
name: dubbo
registry:
#声明注册中心的软件类型和ip端口号
address: nacos://localhost:8848
consumer:
#当项目启动时,作为消费者,是否要检查所有远程服务可用,false表示不检查
check: false

seata:
tx-service-group: csmall_group #定义分组名称,一般是为了区分项目
service:
vgroup-mapping:
csmall_group: default #csmall_group组使用默认的Seata配置完成事务
grouplist:
default: localhost:8091 #设置Seata所在的地址,默认端口是8091

XML依赖

nacos依赖

1
2
3
4
5
<!--nacos依赖-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>

dubbo依赖

1
2
3
4
5
<!-- 添加dubbo依赖-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-dubbo</artifactId>
</dependency>

seata依赖

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!--添加seata依赖-->
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
</dependency>
<!--Seata完成分布式事务需要的两个相关依赖(Seata需要下载下面两个依赖中的资源)-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>

sentinel依赖

1
2
3
4
5
<!--添加sentinel依赖-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>

</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.7.RELEASE</version>
<configuration>
<mainClass>cn.tedu.csmall.stock.CsmallStockApplication</mainClass>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>