Skip to content

Commit 7770689

Browse files
author
YunaiV
committed
增加 Swagger Dubbo 到目录
1 parent 69a9807 commit 7770689

File tree

12 files changed

+226
-2
lines changed

12 files changed

+226
-2
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
* [《芋道 Spring Cloud 服务网关 Spring Cloud Gateway 入门》](http://www.iocoder.cn/Spring-Cloud/Spring-Cloud-Gateway/?github) 对应 [labx-08-spring-cloud-gateway](https://github.com/YunaiV/SpringBoot-Labs/tree/master/labx-08-spring-cloud-gateway)
186186
* [《芋道 Spring Cloud 链路追踪 SkyWalking 入门》](http://www.iocoder.cn/Spring-Cloud/SkyWalking/?github) 对应 [labx-14](https://github.com/YunaiV/SpringBoot-Labs/tree/master/labx-14)
187187
* [《芋道 Dubbo Admin 快速入门》](http://www.iocoder.cn/Dubbo/Admin/?github)
188+
* [《芋道 Dubbo Swagger 快速入门》](http://www.iocoder.cn/Dubbo/Swagger/?github) 对应 [swagger-dubbo](https://github.com/YunaiV/swagger-dubbo)
188189

189190
# Spring Cloud 专栏
190191

@@ -274,6 +275,7 @@
274275
* [《芋道 Spring Boot Dubbo 入门》](http://www.iocoder.cn/Spring-Boot/Dubbo/?github) 对应 [lab-30](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-30)
275276
* [《芋道 Spring Cloud Alibaba 服务调用 Dubbo 入门》](http://www.iocoder.cn/Spring-Cloud-Alibaba/Dubbo/?github) 对应 [labx-07-spring-cloud-alibaba-dubbo](https://github.com/YunaiV/SpringBoot-Labs/tree/master/labx-07-spring-cloud-alibaba-dubbo)
276277
* [《性能测试 —— Dubbo 基准测试》](http://www.iocoder.cn/Performance-Testing/Dubbo-benchmark/?github)
278+
* [《芋道 Dubbo Swagger 快速入门》](http://www.iocoder.cn/Dubbo/Swagger/?github) 对应 [swagger-dubbo](https://github.com/YunaiV/swagger-dubbo)
277279

278280
## 注册中心
279281

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.1.3.RELEASE</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<artifactId>lab-07-spring-data-redis-unit-test</artifactId>
14+
15+
<dependencies>
16+
17+
<!-- 实现对 Redisson 的自动化配置 -->
18+
<dependency>
19+
<groupId>org.redisson</groupId>
20+
<artifactId>redisson-spring-boot-starter</artifactId>
21+
<version>3.11.3</version>
22+
</dependency>
23+
24+
<!-- 方便等会写单元测试 -->
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter-test</artifactId>
28+
<scope>test</scope>
29+
</dependency>
30+
31+
<!-- 等会示例会使用 fastjson 作为 JSON 序列化的工具 -->
32+
<dependency>
33+
<groupId>com.alibaba</groupId>
34+
<artifactId>fastjson</artifactId>
35+
<version>1.2.61</version>
36+
</dependency>
37+
38+
<!-- Spring Data Redis 默认使用 Jackson 作为 JSON 序列化的工具 -->
39+
<dependency>
40+
<groupId>com.fasterxml.jackson.core</groupId>
41+
<artifactId>jackson-databind</artifactId>
42+
</dependency>
43+
44+
<dependency>
45+
<groupId>commons-io</groupId>
46+
<artifactId>commons-io</artifactId>
47+
<version>2.6</version>
48+
</dependency>
49+
50+
<!-- 内嵌 Redis 服务,用于单元测试 -->
51+
<dependency>
52+
<groupId>it.ozimov</groupId>
53+
<artifactId>embedded-redis</artifactId>
54+
<version>0.7.2</version>
55+
<scope>test</scope>
56+
</dependency>
57+
58+
</dependencies>
59+
60+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package cn.iocoder.springboot.labs.lab10.springdatarediswithjedis;
2+
3+
import org.springframework.boot.autoconfigure.SpringBootApplication;
4+
5+
@SpringBootApplication
6+
//@EnableTransactionManagement
7+
public class Application {
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cn.iocoder.springboot.labs.lab10.springdatarediswithjedis.config;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.data.redis.connection.RedisConnectionFactory;
6+
import org.springframework.data.redis.core.RedisTemplate;
7+
import org.springframework.data.redis.serializer.RedisSerializer;
8+
9+
@Configuration
10+
public class RedisConfiguration {
11+
12+
@Bean
13+
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
14+
// 创建 RedisTemplate 对象
15+
RedisTemplate<String, Object> template = new RedisTemplate<>();
16+
17+
// 设置开启事务支持
18+
template.setEnableTransactionSupport(true);
19+
20+
// 设置 RedisConnection 工厂。😈 它就是实现多种 Java Redis 客户端接入的秘密工厂。感兴趣的胖友,可以自己去撸下。
21+
template.setConnectionFactory(factory);
22+
23+
// 使用 String 序列化方式,序列化 KEY 。
24+
template.setKeySerializer(RedisSerializer.string());
25+
26+
// 使用 JSON 序列化方式(库是 Jackson ),序列化 VALUE 。
27+
template.setValueSerializer(RedisSerializer.json());
28+
return template;
29+
}
30+
31+
// Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
32+
// ObjectMapper objectMapper = new ObjectMapper();// <1>
33+
//// objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
34+
//// objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
35+
//
36+
// jackson2JsonRedisSerializer.setObjectMapper(objectMapper);
37+
// template.setValueSerializer(jackson2JsonRedisSerializer);
38+
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cn.iocoder.springboot.labs.lab10.springdatarediswithjedis.util;
2+
3+
import com.alibaba.fastjson.JSON;
4+
5+
/**
6+
* JSON 工具类
7+
*/
8+
public class JSONUtil {
9+
10+
public static <T> T parseObject(String text, Class<T> clazz) {
11+
return JSON.parseObject(text, clazz);
12+
}
13+
14+
public static String toJSONString(Object javaObject) {
15+
return JSON.toJSONString(javaObject);
16+
}
17+
18+
public static byte[] toJSONBytes(Object javaObject) {
19+
return JSON.toJSONBytes(javaObject);
20+
}
21+
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
spring:
2+
# 对应 RedisProperties 类
3+
redis:
4+
host: 127.0.0.1
5+
port: 6379
6+
# password: # Redis 服务器密码,默认为空。生产中,一定要设置 Redis 密码!
7+
database: 0 # Redis 数据库号,默认为 0 。
8+
timeout: 0 # Redis 连接超时时间,单位:毫秒。
9+
# 对应 RedissonProperties 类
10+
# redisson:
11+
# config: classpath:redisson.yml # 具体的每个配置项,见 org.redisson.config.Config 类。

lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/main/resources/redisson.yml

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package cn.iocoder.springboot.labs.lab10.springdatarediswithjedis;
2+
3+
import cn.iocoder.springboot.labs.lab10.springdatarediswithjedis.config.TestRedisConfiguration;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.boot.test.context.SpringBootTest;
9+
import org.springframework.dao.DataAccessException;
10+
import org.springframework.data.redis.connection.RedisConnection;
11+
import org.springframework.data.redis.core.RedisCallback;
12+
import org.springframework.data.redis.core.RedisTemplate;
13+
import org.springframework.data.redis.core.StringRedisTemplate;
14+
import org.springframework.test.context.junit4.SpringRunner;
15+
16+
@RunWith(SpringRunner.class)
17+
@SpringBootTest(classes = TestRedisConfiguration.class)
18+
public class Test01 {
19+
20+
@Autowired
21+
private StringRedisTemplate stringRedisTemplate;
22+
23+
@Autowired
24+
private RedisTemplate redisTemplate;
25+
26+
// @Autowired
27+
// private RedisServer server;
28+
29+
@Test
30+
public void test01() {
31+
// 写入
32+
stringRedisTemplate.opsForValue().set("yunai", "shuai");
33+
// 读取
34+
String value = stringRedisTemplate.opsForValue().get("yunai");
35+
Assert.assertEquals("值不匹配", "shuai", value);
36+
37+
// 测试重启后读取
38+
redisTemplate.execute(new RedisCallback() {
39+
@Override
40+
public Object doInRedis(RedisConnection connection) throws DataAccessException {
41+
connection.flushDb();
42+
return "";
43+
}
44+
});
45+
}
46+
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package cn.iocoder.springboot.labs.lab10.springdatarediswithjedis.config;
2+
3+
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
4+
import org.springframework.boot.test.context.TestConfiguration;
5+
import redis.embedded.RedisServer;
6+
7+
import javax.annotation.PostConstruct;
8+
import javax.annotation.PreDestroy;
9+
10+
@TestConfiguration
11+
public class TestRedisConfiguration {
12+
13+
private RedisServer redisServer;
14+
15+
public TestRedisConfiguration(RedisProperties redisProperties) {
16+
this.redisServer = new RedisServer(redisProperties.getPort());
17+
}
18+
19+
// @Bean
20+
// public RedisServer redisServer() {
21+
// return redisServer;
22+
// }
23+
24+
@PostConstruct
25+
public void postConstruct() {
26+
redisServer.start();
27+
}
28+
29+
@PreDestroy
30+
public void preDestroy() {
31+
redisServer.stop();
32+
}
33+
34+
}

lab-11-spring-data-redis/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<modules>
1515
<module>lab-07-spring-data-redis-with-jedis</module>
1616
<module>lab-07-spring-data-redis-with-redisson</module>
17+
<module>lab-07-spring-data-redis-unit-test</module>
1718
</modules>
1819

1920

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<http://www.iocoder.cn/Dubbo/Swagger/?github>

pom.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@
7676
<!-- <module>lab-66</module>-->
7777
<!-- <module>lab-67</module>-->
7878
<!-- <module>lab-68-spring-security-oauth</module>-->
79-
<module>lab-69-proxy</module>
80-
79+
<!-- <module>lab-69-proxy</module>-->
8180

8281
<!-- Spring Cloud 示例 -->
8382
<!-- <module>labx-01-spring-cloud-alibaba-nacos-discovery</module>-->

0 commit comments

Comments
 (0)