赞
踩
1、创建项目时选择Spring Initializr

2、填好相关信息

3、在依赖库中勾选如下内容

4、填写项目名称

5、把application.properties文件修改成application.yml
以下的环境配置,都是在application.yml中进行。特别的地方,会另作说明。
server:
tomcat:
uri-encoding: UTF-8
threads:
max: 200 #最大线程数量
min-spare: 30 #最小
connection-timeout: 5000ms
port: 8080
servlet:
context-path: /emos-wx-api #项目部署路径
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource #阿里特有的DruidDataSource连接池
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/emos?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
username: root
password: root #本地数据库的用户名和密码
initial-size: 8 #数据库连接池的数量
max-active: 16
min-idle: 8
max-wait: 60000
test-while-idle: true #检测连接是否有效
test-on-borrow: false
test-on-return: false
然后在 pom.xml文件中配置好阿里巴巴的Druid连接池所需要的依赖库。
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.13</version>
</dependency>
spring:
#这里省略MySQL配置信息
redis:
database: 0 #使用0号数据库
host: localhost
port: 6379
password: abc123456 #redis端口的访问密码
jedis:
pool:
max-active: 1000 #设置Redis的连接池
max-wait: -1ms
max-idle: 16 #最大空闲连接数
min-idle: 8
spring:
#这里省略MySQL配置信息
#这里省略Redis配置信息
data:
mongodb:
host: localhost
port: 27017
database: emos
authentication-database: admin
username: admin
password: abc123456
在连接mongoDB的时候,要打开软件:

如下图,出现如下字段表示已完成。

完整的application.yml文件如下:
server: tomcat: uri-encoding: UTF-8 threads: max: 200 min-spare: 30 connection-timeout: 5000ms port: 8080 servlet: context-path: /emos-wx-api spring: datasource: type: com.alibaba.druid.pool.DruidDataSource druid: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/emos?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC username: root password: root initial-size: 8 max-active: 16 min-idle: 8 max-wait: 60000 test-while-idle: true test-on-borrow: false test-on-return: false redis: database: 0 host: localhost port: 6379 password: abc123456 jedis: pool: max-active: 1000 max-wait: -1ms max-idle: 16 min-idle: 8 data: mongodb: host: localhost port: 27017 database: emos authentication-database: admin username: admin password: abc123456
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。