mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-13 22:09:00 +08:00
⚡ 优化代码,删除无用引入和错误注解@NotBlank
This commit is contained in:
1 parent
075c31a508
commit
388ff2a7ca
6 files changed
+28
-29
No files matched your search
+10
-6
@@ -1,10 +1,5 @@
|
||||
package com.pig4cloud.pigx.common.datasource.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import javax.annotation.PostConstruct;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.mysql.cj.jdbc.Driver;
|
||||
import com.pig4cloud.pigx.common.datasource.support.DataSourceConstants;
|
||||
@@ -13,12 +8,19 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.jasypt.encryption.StringEncryptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.transaction.ChainedTransactionManager;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.annotation.TransactionManagementConfigurer;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2019-03-31
|
||||
@@ -89,7 +91,9 @@ public class DynamicDataSourceConfig implements TransactionManagementConfigurer
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager txManager() {
|
||||
return new DataSourceTransactionManager(dataSource());
|
||||
DataSourceTransactionManager transactionManager
|
||||
= new DataSourceTransactionManager(dataSource());
|
||||
return new ChainedTransactionManager(transactionManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-9
@@ -1,17 +1,15 @@
|
||||
package com.pig4cloud.pigx.common.datasource.config;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import com.pig4cloud.pigx.common.datasource.support.DynamicDataSourceContextHolder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.core.HashOperations;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2019-05-18
|
||||
@@ -22,13 +20,9 @@ import org.springframework.web.servlet.HandlerInterceptor;
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class DynamicDatasourceInterceptor implements HandlerInterceptor {
|
||||
private final RedisTemplate redisTemplate;
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||
redisTemplate.setHashValueSerializer(new Jackson2JsonRedisSerializer<>(String.class));
|
||||
HashOperations<String, String, String> vo = redisTemplate.opsForHash();
|
||||
// String dbName = vo.get("db_route_key", 1);
|
||||
DynamicDataSourceContextHolder.setDataSourceType(1);
|
||||
log.info("数据源切换:{}", 1);
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user