org.springframework.boot
spring-boot-starter-parent
2.3.8.RELEASE
实验中发现这样定义后其实再引入依赖的时候就不用写版本了
Hoxton.SR9
2.2.5.RELEASE
1.8
true
1.18.8
2.0.2
3.1.1
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
org.junit.vintage
junit-vintage-engine
需要安装的依赖为:
org.projectlombok
lombok
provided
需要安装的依赖为:
com.baomidou
mybatis-plus-boot-starter
${mybatis.plus.version}
在pom.xml中添加如下依赖
mysql
mysql-connector-java
在application.yml中添加数据库连接配置
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.211.136:3306/leadnews_admin?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=&serverTimezone=Asia/Shanghai
username: root
password: 123456
在启动类上添加mapper文件夹所在的路径
@MapperScan(basePackages = "com.jjw.mapper")
io.springfox
springfox-swagger2
2.9.2
io.springfox
springfox-swagger-ui
2.9.2
另外需要一个配合类,内容如下:
package com.jjw.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.HashSet;
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
@Bean
public Docket buildDocket() {
HashSet strings = new HashSet<>();
strings.add("application/json");
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(buildApiInfo())
//设置返回值数据类型为json
.produces(strings)
.select()
// 要扫描的API(Controller)基础包
// 可以只扫到controller这个包即,com.jjw.controller
.apis(RequestHandlerSelectors.basePackage("com.jjw"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo buildApiInfo() {
Contact contact = new Contact("jjw","","");
return new ApiInfoBuilder()
.title("jjw-平台管理API文档")
.description("平台管理服务api")
.contact(contact)
.version("1.0.0").build();
}
}
打开方式:http://localhost:7000/swagger-ui.html
org.springframework.boot
spring-boot-starter-validation
com.github.xiaoymin
knife4j-spring-boot-starter
2.0.2
配置类:
package com.jjw.config;
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.HashSet;
@Configuration
@EnableSwagger2
@EnableKnife4j
@Import(BeanValidatorPluginsConfiguration.class)
public class SwaggerConfiguration {
@Bean
public Docket buildDocket() {
HashSet strings = new HashSet<>();
strings.add("application/json");
Docket docket=new Docket(DocumentationType.SWAGGER_2)
.apiInfo(buildApiInfo())
//设置返回数据类型
.produces(strings)
//分组名称
.groupName("1.0")
.select()
//这里指定Controller扫描包路径
.apis(RequestHandlerSelectors.basePackage("com.jjw.controller"))
.paths(PathSelectors.any())
.build();
return docket;
}
private ApiInfo buildApiInfo() {
Contact contact = new Contact("jjw","","");
return new ApiInfoBuilder()
.title("jjw-平台管理API文档")
.description("平台管理服务api")
.contact(contact)
.version("1.0.0").build();
}
}
其他参数的使用和swagger一样
com.alibaba.cloud
spring-cloud-starter-alibaba-nacos-discovery
spring:
application:
name: leadnews-admin
profiles: dev
cloud:
nacos:
server-addr: 192.168.211.136:8848
discovery:
server-addr: ${spring.cloud.nacos.server-addr}
io.jsonwebtoken
jjwt
0.9.1
org.springframework.cloud
spring-cloud-starter-gateway
这里边需要注意的是如果,引入此依赖,并且此服务中用到其他的服务中的包,且其他服务中的包又引入或者包含spring-boot-starter-web这个依赖,则需要将其排除掉,例如:
com.jjw
result-content
1.0-SNAPSHOT
org.springframework.boot
spring-boot-starter-web
com.jjw
swagger-content
org.springframework.cloud
spring-cloud-starter-openfeign
io.github.openfeign
feign-okhttp
在需要用到feign的微服务中配置如下即可:
feign:
client:
config:
default: # default指定的是所有的 被调用方 都设置为该配置超时时间,可以设置为某一个微服务对应的服务名
connectTimeout: 5000 # 链接超时时间
readTimeout: 5000 # 读取的超时时间
okhttp:
enabled: true
httpclient:
enabled: false
com.github.tobato
fastdfs-client
1.26.5
单独测试时只需要在yml中有如下配置即可:
fdfs:
so-timeout: 1501
connect-timeout: 601
thumb-image: #缩略图生成参数
width: 150
height: 150
tracker-list: #TrackerList参数,支持多个
- 192.168.211.136:22122
多个服务一起配置的话很有可能需要多一个数据库方面的配置如下:
spring:
profiles:
active: dev
---
server:
port: 9005
spring:
application:
name: leadnews-dfs
profiles: dev
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.211.136:3306/你的数据库名称?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=&serverTimezone=Asia/Shanghai
username: root
password: 123456
cloud:
nacos:
server-addr: 192.168.211.136:8848
discovery:
server-addr: ${spring.cloud.nacos.server-addr}
servlet:
multipart:
max-file-size: 10MB
max-request-size: 10MB
# fastdfs的配置
fdfs:
so-timeout: 1501
connect-timeout: 601
thumb-image: #缩略图生成参数
width: 150
height: 150
tracker-list:
- 192.168.211.136:22122 #TrackerList参数,支持多个
web-server-url: http://192.168.211.136/ # 设置前缀路径
logging:
level.com: debug
com.alibaba
fastjson
1.2.58
org.springframework.kafka
spring-kafka
org.springframework.kafka
spring-kafka-test
test
# 配置,yml中
spring:
kafka:
# 配置连接到服务端集群的配置项 ip:port,ip:port
bootstrap-servers: 192.168.211.136:9092
consumer:
# auto-commit-interval: 100
auto-offset-reset: earliest
# enable-auto-commit: true
group-id: test-consumer-group # 控制是否按组接收消息
# 默认值即为字符串
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
# 默认值即为字符串
value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
producer:
batch-size: 16384
buffer-memory: 33554432
key-serializer: org.apache.kafka.common.serialization.StringSerializer
retries: 0
value-serializer: org.apache.kafka.common.serialization.StringSerializer
com.xuxueli
xxl-job-core
2.1.2
@Field(type = FieldType.Text, index = true,analyzer = “ik_smart”, searchAnalyzer = “ik_smart”)
解释如下:
org.springframework.boot
spring-boot-starter-data-elasticsearch
yml中和cloud平级
elasticsearch:
rest:
uris:
- http://192.168.211.136:9200
org.apache.kafka
kafka-streams
2.5.1