mirror of
https://gitee.com/yudaocode/SpringBoot-Labs.git
synced 2026-09-03 05:53:54 +08:00
增加 Swagger Dubbo 到目录
This commit is contained in:
@@ -185,6 +185,7 @@
|
||||
* [《芋道 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)
|
||||
* [《芋道 Spring Cloud 链路追踪 SkyWalking 入门》](http://www.iocoder.cn/Spring-Cloud/SkyWalking/?github) 对应 [labx-14](https://github.com/YunaiV/SpringBoot-Labs/tree/master/labx-14)
|
||||
* [《芋道 Dubbo Admin 快速入门》](http://www.iocoder.cn/Dubbo/Admin/?github)
|
||||
* [《芋道 Dubbo Swagger 快速入门》](http://www.iocoder.cn/Dubbo/Swagger/?github) 对应 [swagger-dubbo](https://github.com/YunaiV/swagger-dubbo)
|
||||
|
||||
# Spring Cloud 专栏
|
||||
|
||||
@@ -274,6 +275,7 @@
|
||||
* [《芋道 Spring Boot Dubbo 入门》](http://www.iocoder.cn/Spring-Boot/Dubbo/?github) 对应 [lab-30](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-30)
|
||||
* [《芋道 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)
|
||||
* [《性能测试 —— Dubbo 基准测试》](http://www.iocoder.cn/Performance-Testing/Dubbo-benchmark/?github)
|
||||
* [《芋道 Dubbo Swagger 快速入门》](http://www.iocoder.cn/Dubbo/Swagger/?github) 对应 [swagger-dubbo](https://github.com/YunaiV/swagger-dubbo)
|
||||
|
||||
## 注册中心
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.3.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>lab-07-spring-data-redis-unit-test</artifactId>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- 实现对 Redisson 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson-spring-boot-starter</artifactId>
|
||||
<version>3.11.3</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 方便等会写单元测试 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- 等会示例会使用 fastjson 作为 JSON 序列化的工具 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.61</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Data Redis 默认使用 Jackson 作为 JSON 序列化的工具 -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 内嵌 Redis 服务,用于单元测试 -->
|
||||
<dependency>
|
||||
<groupId>it.ozimov</groupId>
|
||||
<artifactId>embedded-redis</artifactId>
|
||||
<version>0.7.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.iocoder.springboot.labs.lab10.springdatarediswithjedis;
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
//@EnableTransactionManagement
|
||||
public class Application {
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package cn.iocoder.springboot.labs.lab10.springdatarediswithjedis.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
|
||||
@Configuration
|
||||
public class RedisConfiguration {
|
||||
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
|
||||
// 创建 RedisTemplate 对象
|
||||
RedisTemplate<String, Object> template = new RedisTemplate<>();
|
||||
|
||||
// 设置开启事务支持
|
||||
template.setEnableTransactionSupport(true);
|
||||
|
||||
// 设置 RedisConnection 工厂。😈 它就是实现多种 Java Redis 客户端接入的秘密工厂。感兴趣的胖友,可以自己去撸下。
|
||||
template.setConnectionFactory(factory);
|
||||
|
||||
// 使用 String 序列化方式,序列化 KEY 。
|
||||
template.setKeySerializer(RedisSerializer.string());
|
||||
|
||||
// 使用 JSON 序列化方式(库是 Jackson ),序列化 VALUE 。
|
||||
template.setValueSerializer(RedisSerializer.json());
|
||||
return template;
|
||||
}
|
||||
|
||||
// Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
|
||||
// ObjectMapper objectMapper = new ObjectMapper();// <1>
|
||||
//// objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||
//// objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
|
||||
//
|
||||
// jackson2JsonRedisSerializer.setObjectMapper(objectMapper);
|
||||
// template.setValueSerializer(jackson2JsonRedisSerializer);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package cn.iocoder.springboot.labs.lab10.springdatarediswithjedis.util;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
/**
|
||||
* JSON 工具类
|
||||
*/
|
||||
public class JSONUtil {
|
||||
|
||||
public static <T> T parseObject(String text, Class<T> clazz) {
|
||||
return JSON.parseObject(text, clazz);
|
||||
}
|
||||
|
||||
public static String toJSONString(Object javaObject) {
|
||||
return JSON.toJSONString(javaObject);
|
||||
}
|
||||
|
||||
public static byte[] toJSONBytes(Object javaObject) {
|
||||
return JSON.toJSONBytes(javaObject);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
spring:
|
||||
# 对应 RedisProperties 类
|
||||
redis:
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
# password: # Redis 服务器密码,默认为空。生产中,一定要设置 Redis 密码!
|
||||
database: 0 # Redis 数据库号,默认为 0 。
|
||||
timeout: 0 # Redis 连接超时时间,单位:毫秒。
|
||||
# 对应 RedissonProperties 类
|
||||
# redisson:
|
||||
# config: classpath:redisson.yml # 具体的每个配置项,见 org.redisson.config.Config 类。
|
||||
@@ -0,0 +1,47 @@
|
||||
package cn.iocoder.springboot.labs.lab10.springdatarediswithjedis;
|
||||
|
||||
import cn.iocoder.springboot.labs.lab10.springdatarediswithjedis.config.TestRedisConfiguration;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.core.RedisCallback;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestRedisConfiguration.class)
|
||||
public class Test01 {
|
||||
|
||||
@Autowired
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
// @Autowired
|
||||
// private RedisServer server;
|
||||
|
||||
@Test
|
||||
public void test01() {
|
||||
// 写入
|
||||
stringRedisTemplate.opsForValue().set("yunai", "shuai");
|
||||
// 读取
|
||||
String value = stringRedisTemplate.opsForValue().get("yunai");
|
||||
Assert.assertEquals("值不匹配", "shuai", value);
|
||||
|
||||
// 测试重启后读取
|
||||
redisTemplate.execute(new RedisCallback() {
|
||||
@Override
|
||||
public Object doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
connection.flushDb();
|
||||
return "";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package cn.iocoder.springboot.labs.lab10.springdatarediswithjedis.config;
|
||||
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import redis.embedded.RedisServer;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
@TestConfiguration
|
||||
public class TestRedisConfiguration {
|
||||
|
||||
private RedisServer redisServer;
|
||||
|
||||
public TestRedisConfiguration(RedisProperties redisProperties) {
|
||||
this.redisServer = new RedisServer(redisProperties.getPort());
|
||||
}
|
||||
|
||||
// @Bean
|
||||
// public RedisServer redisServer() {
|
||||
// return redisServer;
|
||||
// }
|
||||
|
||||
@PostConstruct
|
||||
public void postConstruct() {
|
||||
redisServer.start();
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void preDestroy() {
|
||||
redisServer.stop();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
<modules>
|
||||
<module>lab-07-spring-data-redis-with-jedis</module>
|
||||
<module>lab-07-spring-data-redis-with-redisson</module>
|
||||
<module>lab-07-spring-data-redis-unit-test</module>
|
||||
</modules>
|
||||
|
||||
|
||||
|
||||
1
lab-30/《芋道 Dubbo Swagger 快速入门》.md
Normal file
1
lab-30/《芋道 Dubbo Swagger 快速入门》.md
Normal file
@@ -0,0 +1 @@
|
||||
<http://www.iocoder.cn/Dubbo/Swagger/?github>
|
||||
3
pom.xml
3
pom.xml
@@ -76,8 +76,7 @@
|
||||
<!-- <module>lab-66</module>-->
|
||||
<!-- <module>lab-67</module>-->
|
||||
<!-- <module>lab-68-spring-security-oauth</module>-->
|
||||
<module>lab-69-proxy</module>
|
||||
|
||||
<!-- <module>lab-69-proxy</module>-->
|
||||
|
||||
<!-- Spring Cloud 示例 -->
|
||||
<!-- <module>labx-01-spring-cloud-alibaba-nacos-discovery</module>-->
|
||||
|
||||
Reference in New Issue
Block a user