feat:
- 添加Redis配置
This commit is contained in:
parent
9239ad51a6
commit
28bba7ed79
21
pom.xml
21
pom.xml
@ -71,12 +71,12 @@
|
|||||||
<artifactId>jakarta.mail</artifactId>
|
<artifactId>jakarta.mail</artifactId>
|
||||||
<version>2.0.1</version>
|
<version>2.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- <dependency>-->
|
<dependency>
|
||||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
<groupId>org.springframework.boot</groupId>
|
||||||
<!-- <artifactId>spring-boot-devtools</artifactId>-->
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
<!-- <scope>runtime</scope>-->
|
<scope>runtime</scope>
|
||||||
<!-- <optional>true</optional>-->
|
<optional>true</optional>
|
||||||
<!-- </dependency>-->
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
@ -138,6 +138,15 @@
|
|||||||
<version>RELEASE</version>
|
<version>RELEASE</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- 对象池,使用redis时必须引入 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-pool2</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@ -0,0 +1,49 @@
|
|||||||
|
package asia.yulinling.workflow.config;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||||
|
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||||
|
import org.springframework.cache.CacheManager;
|
||||||
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||||
|
import org.springframework.data.redis.cache.RedisCacheManager;
|
||||||
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||||
|
import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||||
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Redis配置类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author YLL
|
||||||
|
* @since 2025/6/17
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@AutoConfigureAfter(RedisAutoConfiguration.class)
|
||||||
|
@EnableCaching
|
||||||
|
public class RedisConfig {
|
||||||
|
@Bean
|
||||||
|
public RedisTemplate<String, Serializable> redisTemplate(RedisConnectionFactory factory) {
|
||||||
|
RedisTemplate<String, Serializable> redisTemplate = new RedisTemplate<>();
|
||||||
|
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||||
|
redisTemplate.setValueSerializer(new StringRedisSerializer());
|
||||||
|
redisTemplate.setConnectionFactory(factory);
|
||||||
|
return redisTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Bean
|
||||||
|
// public CacheManager cacheManager(RedisConnectionFactory factory) {
|
||||||
|
// RedisCacheConfiguration configuration = RedisCacheConfiguration.defaultCacheConfig();
|
||||||
|
// RedisCacheConfiguration redisCacheConfiguration = configuration.serializeKeysWith(
|
||||||
|
// RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())
|
||||||
|
// ).serializeValuesWith(
|
||||||
|
// RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer()));
|
||||||
|
// return RedisCacheManager.builder(factory).cacheDefaults(redisCacheConfiguration).build();
|
||||||
|
// }
|
||||||
|
}
|
||||||
@ -88,5 +88,4 @@ public class User {
|
|||||||
*/
|
*/
|
||||||
@TableField("last_login_time")
|
@TableField("last_login_time")
|
||||||
private Date lastLoginTime;
|
private Date lastLoginTime;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,6 @@ import org.springframework.util.AntPathMatcher;
|
|||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.method.HandlerMethod;
|
import org.springframework.web.method.HandlerMethod;
|
||||||
import org.springframework.web.servlet.mvc.condition.PathPatternsRequestCondition;
|
import org.springframework.web.servlet.mvc.condition.PathPatternsRequestCondition;
|
||||||
import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition;
|
|
||||||
import org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition;
|
import org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition;
|
||||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
||||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||||
@ -75,10 +74,14 @@ public class JwtRbacAuthenticationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查请求在Controller中是否存在
|
||||||
|
*
|
||||||
|
* @param request 请求
|
||||||
|
*/
|
||||||
private void checkRequest(HttpServletRequest request) {
|
private void checkRequest(HttpServletRequest request) {
|
||||||
String method = request.getMethod();
|
String method = request.getMethod();
|
||||||
Map<String, List<String>> urlMapping = getAllUrlMapping();
|
Map<String, List<String>> urlMapping = getAllUrlMapping();
|
||||||
log.info("方法" + method + "url" + urlMapping.toString());
|
|
||||||
|
|
||||||
for (String url : urlMapping.keySet()) {
|
for (String url : urlMapping.keySet()) {
|
||||||
AntPathMatcher antPathMatcher = new AntPathMatcher();
|
AntPathMatcher antPathMatcher = new AntPathMatcher();
|
||||||
@ -114,9 +117,9 @@ public class JwtRbacAuthenticationService {
|
|||||||
List<String> httpMethods = methodsCondition.getMethods().stream()
|
List<String> httpMethods = methodsCondition.getMethods().stream()
|
||||||
.map(Enum::toString)
|
.map(Enum::toString)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
urlTemplates.forEach(url -> {
|
urlTemplates.forEach(url ->
|
||||||
urlMapping.put(url.toString(), httpMethods);
|
urlMapping.put(url.toString(), httpMethods)
|
||||||
});
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
log.info("urlMapping :{}", urlMapping);
|
log.info("urlMapping :{}", urlMapping);
|
||||||
|
|||||||
@ -4,7 +4,7 @@ server.port=8080
|
|||||||
# mysql配置
|
# mysql配置
|
||||||
spring.datasource.url=jdbc:mysql://122.152.201.90:9912/workflow?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&failOverReadOnly=false&serverTimezone=GMT%2B8
|
spring.datasource.url=jdbc:mysql://122.152.201.90:9912/workflow?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&failOverReadOnly=false&serverTimezone=GMT%2B8
|
||||||
spring.datasource.username=root
|
spring.datasource.username=root
|
||||||
spring.datasource.password=0andrx
|
spring.datasource.password=ENC(lLJgIEE5YJuSKnOpFBC4NFL+iqZZK97573fvgC7hZ8u3S6o/TlK15WfjnKTPOrQO)
|
||||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
spring.sql.init.mode=always
|
spring.sql.init.mode=always
|
||||||
spring.sql.init.continue-on-error=true
|
spring.sql.init.continue-on-error=true
|
||||||
@ -19,6 +19,15 @@ spring.datasource.hikari.idle-timeout=30000
|
|||||||
spring.datasource.hikari.pool-name=MyAppHikariCP
|
spring.datasource.hikari.pool-name=MyAppHikariCP
|
||||||
spring.datasource.hikari.max-lifetime=300000
|
spring.datasource.hikari.max-lifetime=300000
|
||||||
spring.datasource.hikari.connection-timeout=30000
|
spring.datasource.hikari.connection-timeout=30000
|
||||||
|
# Redis配置
|
||||||
|
spring.data.redis.host=122.152.201.90
|
||||||
|
spring.data.redis.port=6379
|
||||||
|
spring.data.redis.password=ENC(lLJgIEE5YJuSKnOpFBC4NFL+iqZZK97573fvgC7hZ8u3S6o/TlK15WfjnKTPOrQO)
|
||||||
|
spring.data.redis.timeout=10000ms
|
||||||
|
spring.data.redis.lettuce.pool.max-active=8
|
||||||
|
spring.data.redis.lettuce.pool.max-wait=-1ms
|
||||||
|
spring.data.redis.lettuce.pool.max-idle=8
|
||||||
|
spring.data.redis.lettuce.pool.min-idle=0
|
||||||
# log配置
|
# log配置
|
||||||
logging.level.asia.yulinling=debug
|
logging.level.asia.yulinling=debug
|
||||||
logging.level.asia.yulinling.workflow.mapper=trace
|
logging.level.asia.yulinling.workflow.mapper=trace
|
||||||
|
|||||||
@ -17,7 +17,7 @@ public class PasswordTest extends WorkFlowMainTests {
|
|||||||
@Test
|
@Test
|
||||||
public void testGeneratePassword() {
|
public void testGeneratePassword() {
|
||||||
// 你的邮箱密码
|
// 你的邮箱密码
|
||||||
String password = "xlwpmlbawpjjdghb";
|
String password = "0andrx";
|
||||||
String encryptPassword = encryptor.encrypt(password);
|
String encryptPassword = encryptor.encrypt(password);
|
||||||
String decryptPassword = encryptor.decrypt(encryptPassword);
|
String decryptPassword = encryptor.decrypt(encryptPassword);
|
||||||
|
|
||||||
|
|||||||
56
src/test/java/asia/yulinling/workflow/RedisTest.java
Normal file
56
src/test/java/asia/yulinling/workflow/RedisTest.java
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package asia.yulinling.workflow;
|
||||||
|
|
||||||
|
import asia.yulinling.workflow.model.entity.User;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Redis测试
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author YLL
|
||||||
|
* @since 2025/6/17
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class RedisTest extends WorkFlowMainTests {
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate<String, Serializable> redisTemplate;
|
||||||
|
@Autowired
|
||||||
|
private StringRedisTemplate stringRedisTemplate;
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRedisTemplate() throws InterruptedException {
|
||||||
|
// CountDownLatch latch = new CountDownLatch(1000);
|
||||||
|
// ExecutorService executorService = Executors.newFixedThreadPool(100);
|
||||||
|
//
|
||||||
|
// IntStream.range(0, 1000).forEach(i -> {
|
||||||
|
// executorService.execute(() -> {
|
||||||
|
// stringRedisTemplate.opsForValue().increment("count", 1);
|
||||||
|
// latch.countDown();
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// latch.await(); // 等待所有线程执行完毕
|
||||||
|
// executorService.shutdown(); // 关闭线程池
|
||||||
|
//
|
||||||
|
// Long count = Long.valueOf(Objects.requireNonNull(stringRedisTemplate.opsForValue().get("count")));
|
||||||
|
// log.info("count: {}", count);
|
||||||
|
//
|
||||||
|
// stringRedisTemplate.opsForValue().set("k1", "v1");
|
||||||
|
// String k1 = stringRedisTemplate.opsForValue().get("k1");
|
||||||
|
// log.info("k1: {}", k1);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user