mirror of
https://gitee.com/incloudcode/yexuejc-springboot.git
synced 2025-10-14 22:17:55 +08:00
更新master
This commit is contained in:
@@ -9,9 +9,9 @@
|
||||
<parent>
|
||||
<groupId>com.yexuejc.springboot</groupId>
|
||||
<artifactId>yexuejc-springboot-parent</artifactId>
|
||||
<version>1.2.0</version>
|
||||
<version>2.1.0</version>
|
||||
<!-- 本地打包:使用相对关联路径 -->
|
||||
<!--<relativePath>../../yexuejc</relativePath>-->
|
||||
<!--<relativePath>../</relativePath>-->
|
||||
</parent>
|
||||
|
||||
<name>${project.artifactId}</name>
|
||||
@@ -23,7 +23,7 @@
|
||||
<dependencies>
|
||||
<!--基础包-->
|
||||
<dependency>
|
||||
<groupId>com.yexuejc.base</groupId>
|
||||
<groupId>top.yexuejc</groupId>
|
||||
<artifactId>yexuejc-base</artifactId>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
|
@@ -1,13 +1,13 @@
|
||||
package com.yexuejc.springboot.base.autoconfigure;
|
||||
|
||||
import com.aliyun.mns.client.MNSClient;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.aliyun.mns.client.MNSClient;
|
||||
|
||||
/**
|
||||
* 阿里云消息服务MNS相关配置
|
||||
*
|
||||
@@ -20,6 +20,7 @@ import com.aliyun.mns.client.MNSClient;
|
||||
@Configuration
|
||||
@ConditionalOnClass(MNSClient.class)
|
||||
@EnableConfigurationProperties(MnsProperties.class)
|
||||
@ConditionalOnProperty(name = "yexuejc.autoconfigure.mns.enable", matchIfMissing = false)
|
||||
public class MnsAutoConfiguration {
|
||||
private final MnsProperties properties;
|
||||
|
||||
|
@@ -1,22 +1,19 @@
|
||||
package com.yexuejc.springboot.base.autoconfigure;
|
||||
|
||||
import org.apache.commons.pool2.impl.GenericObjectPool;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisProperties.Cluster;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisProperties.Sentinel;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.data.redis.connection.RedisClusterConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.RedisNode;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisPassword;
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||
import org.springframework.data.redis.connection.jedis.JedisClientConfiguration;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnection;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisOperations;
|
||||
@@ -24,32 +21,24 @@ import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 对redis封装
|
||||
* 多个database配置
|
||||
*
|
||||
* @author maxf
|
||||
* @version 1.0
|
||||
* @ClassName MutiRedisAutoConfiguration
|
||||
* @PackageName com.yexuejc.springboot.base.autoconfigure
|
||||
* @Description
|
||||
* @date 2018/11/1 10:31
|
||||
* @date 2018/9/26 15:27
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({JedisConnection.class, RedisOperations.class, Jedis.class})
|
||||
@EnableConfigurationProperties(RedisProperties.class)
|
||||
@Order(1)
|
||||
@ConditionalOnProperty(name = "yexuejc.autoconfigure.redis.enable", matchIfMissing = false)
|
||||
public class MutiRedisAutoConfiguration {
|
||||
|
||||
public static final String BEAN_REDIS_FACTORY0 = "redisConnectionFactory";
|
||||
public static final String BEAN_REDIS_TEMPLATE0 = "redisTemplate";
|
||||
public static final String BEAN_REDIS_STRING_TEMPLATE0 = "stringRedisTemplate";
|
||||
@@ -82,207 +71,94 @@ public class MutiRedisAutoConfiguration {
|
||||
public static final String BEAN_REDIS_TEMPLATE9 = "redis-template-9";
|
||||
public static final String BEAN_REDIS_STRING_TEMPLATE9 = "redis-string-template-9";
|
||||
|
||||
/**
|
||||
* Redis connection configuration.
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(GenericObjectPool.class)
|
||||
protected static class RedisConnectionConfiguration {
|
||||
|
||||
private final RedisProperties properties;
|
||||
|
||||
private final RedisSentinelConfiguration sentinelConfiguration;
|
||||
|
||||
private final RedisClusterConfiguration clusterConfiguration;
|
||||
|
||||
public RedisConnectionConfiguration(RedisProperties properties,
|
||||
ObjectProvider<RedisSentinelConfiguration> sentinelConfiguration,
|
||||
ObjectProvider<RedisClusterConfiguration> clusterConfiguration) {
|
||||
public RedisConnectionConfiguration(RedisProperties properties) {
|
||||
this.properties = properties;
|
||||
this.sentinelConfiguration = sentinelConfiguration.getIfAvailable();
|
||||
this.clusterConfiguration = clusterConfiguration.getIfAvailable();
|
||||
}
|
||||
|
||||
@Primary
|
||||
@Bean(BEAN_REDIS_FACTORY0)
|
||||
@ConditionalOnProperty(name = "yexuejc.redis.db0", matchIfMissing = true)
|
||||
public JedisConnectionFactory redisConnectionFactory0() throws UnknownHostException {
|
||||
return applyProperties(createJedisConnectionFactory(), 0);
|
||||
return createJedisConnectionFactory(0);
|
||||
}
|
||||
|
||||
@Bean(BEAN_REDIS_FACTORY1)
|
||||
@ConditionalOnProperty(name = "yexuejc.redis.db1")
|
||||
public JedisConnectionFactory redisConnectionFactory1() throws UnknownHostException {
|
||||
return applyProperties(createJedisConnectionFactory(), 1);
|
||||
return createJedisConnectionFactory(1);
|
||||
}
|
||||
|
||||
@Bean(BEAN_REDIS_FACTORY2)
|
||||
@ConditionalOnProperty(name = "yexuejc.redis.db2")
|
||||
public JedisConnectionFactory redisConnectionFactory2() throws UnknownHostException {
|
||||
return applyProperties(createJedisConnectionFactory(), 2);
|
||||
return createJedisConnectionFactory(2);
|
||||
}
|
||||
|
||||
@Bean(BEAN_REDIS_FACTORY3)
|
||||
@ConditionalOnProperty(name = "yexuejc.redis.db3")
|
||||
public JedisConnectionFactory redisConnectionFactory3() throws UnknownHostException {
|
||||
return applyProperties(createJedisConnectionFactory(), 3);
|
||||
return createJedisConnectionFactory(3);
|
||||
}
|
||||
|
||||
@Bean(BEAN_REDIS_FACTORY4)
|
||||
@ConditionalOnProperty(name = "yexuejc.redis.db4")
|
||||
public JedisConnectionFactory redisConnectionFactory4() throws UnknownHostException {
|
||||
return applyProperties(createJedisConnectionFactory(), 4);
|
||||
return createJedisConnectionFactory(4);
|
||||
}
|
||||
|
||||
@Bean(BEAN_REDIS_FACTORY5)
|
||||
@ConditionalOnProperty(name = "yexuejc.redis.db5")
|
||||
public JedisConnectionFactory redisConnectionFactory5() throws UnknownHostException {
|
||||
return applyProperties(createJedisConnectionFactory(), 5);
|
||||
return createJedisConnectionFactory(5);
|
||||
}
|
||||
|
||||
@Bean(BEAN_REDIS_FACTORY6)
|
||||
@ConditionalOnProperty(name = "yexuejc.redis.db6")
|
||||
public JedisConnectionFactory redisConnectionFactory6() throws UnknownHostException {
|
||||
return applyProperties(createJedisConnectionFactory(), 6);
|
||||
return createJedisConnectionFactory(6);
|
||||
}
|
||||
|
||||
@Bean(BEAN_REDIS_FACTORY7)
|
||||
@ConditionalOnProperty(name = "yexuejc.redis.db7")
|
||||
public JedisConnectionFactory redisConnectionFactory7() throws UnknownHostException {
|
||||
return applyProperties(createJedisConnectionFactory(), 7);
|
||||
return createJedisConnectionFactory(7);
|
||||
}
|
||||
|
||||
@Bean(BEAN_REDIS_FACTORY8)
|
||||
@ConditionalOnProperty(name = "yexuejc.redis.db8")
|
||||
public JedisConnectionFactory redisConnectionFactory8() throws UnknownHostException {
|
||||
return applyProperties(createJedisConnectionFactory(), 8);
|
||||
return createJedisConnectionFactory(8);
|
||||
}
|
||||
|
||||
@Bean(BEAN_REDIS_FACTORY9)
|
||||
@ConditionalOnProperty(name = "yexuejc.redis.db9")
|
||||
public JedisConnectionFactory redisConnectionFactory9() throws UnknownHostException {
|
||||
return applyProperties(createJedisConnectionFactory(), 9);
|
||||
return createJedisConnectionFactory(9);
|
||||
}
|
||||
|
||||
protected final JedisConnectionFactory applyProperties(JedisConnectionFactory factory, int database) {
|
||||
configureConnection(factory);
|
||||
if (this.properties.isSsl()) {
|
||||
factory.setUseSsl(true);
|
||||
}
|
||||
factory.setDatabase(database);
|
||||
if (this.properties.getTimeout() > 0) {
|
||||
factory.setTimeout(this.properties.getTimeout());
|
||||
}
|
||||
private JedisConnectionFactory createJedisConnectionFactory(int database) {
|
||||
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
|
||||
redisStandaloneConfiguration.setHostName(properties.getHost());
|
||||
redisStandaloneConfiguration.setPort(properties.getPort());
|
||||
redisStandaloneConfiguration.setDatabase(database);
|
||||
redisStandaloneConfiguration.setPassword(RedisPassword.of(properties.getPassword()));
|
||||
|
||||
JedisClientConfiguration.JedisClientConfigurationBuilder jedisClientConfiguration = JedisClientConfiguration.builder();
|
||||
|
||||
JedisConnectionFactory factory = new JedisConnectionFactory(redisStandaloneConfiguration,
|
||||
jedisClientConfiguration.build());
|
||||
return factory;
|
||||
}
|
||||
|
||||
private void configureConnection(JedisConnectionFactory factory) {
|
||||
if (StringUtils.hasText(this.properties.getUrl())) {
|
||||
configureConnectionFromUrl(factory);
|
||||
} else {
|
||||
factory.setHostName(this.properties.getHost());
|
||||
factory.setPort(this.properties.getPort());
|
||||
if (this.properties.getPassword() != null) {
|
||||
factory.setPassword(this.properties.getPassword());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void configureConnectionFromUrl(JedisConnectionFactory factory) {
|
||||
String url = this.properties.getUrl();
|
||||
if (url.startsWith("rediss://")) {
|
||||
factory.setUseSsl(true);
|
||||
}
|
||||
try {
|
||||
URI uri = new URI(url);
|
||||
factory.setHostName(uri.getHost());
|
||||
factory.setPort(uri.getPort());
|
||||
if (uri.getUserInfo() != null) {
|
||||
String password = uri.getUserInfo();
|
||||
int index = password.lastIndexOf(":");
|
||||
if (index >= 0) {
|
||||
password = password.substring(index + 1);
|
||||
}
|
||||
factory.setPassword(password);
|
||||
}
|
||||
} catch (URISyntaxException ex) {
|
||||
throw new IllegalArgumentException("Malformed 'spring.redis.url' " + url, ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected final RedisSentinelConfiguration getSentinelConfig() {
|
||||
if (this.sentinelConfiguration != null) {
|
||||
return this.sentinelConfiguration;
|
||||
}
|
||||
Sentinel sentinelProperties = this.properties.getSentinel();
|
||||
if (sentinelProperties != null) {
|
||||
RedisSentinelConfiguration config = new RedisSentinelConfiguration();
|
||||
config.master(sentinelProperties.getMaster());
|
||||
config.setSentinels(createSentinels(sentinelProperties));
|
||||
return config;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link RedisClusterConfiguration} if necessary.
|
||||
*
|
||||
* @return {@literal null} if no cluster settings are set.
|
||||
*/
|
||||
protected final RedisClusterConfiguration getClusterConfiguration() {
|
||||
if (this.clusterConfiguration != null) {
|
||||
return this.clusterConfiguration;
|
||||
}
|
||||
if (this.properties.getCluster() == null) {
|
||||
return null;
|
||||
}
|
||||
Cluster clusterProperties = this.properties.getCluster();
|
||||
RedisClusterConfiguration config = new RedisClusterConfiguration(clusterProperties.getNodes());
|
||||
|
||||
if (clusterProperties.getMaxRedirects() != null) {
|
||||
config.setMaxRedirects(clusterProperties.getMaxRedirects());
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
private List<RedisNode> createSentinels(Sentinel sentinel) {
|
||||
List<RedisNode> nodes = new ArrayList<RedisNode>();
|
||||
for (String node : StringUtils.commaDelimitedListToStringArray(sentinel.getNodes())) {
|
||||
try {
|
||||
String[] parts = StringUtils.split(node, ":");
|
||||
Assert.state(parts.length == 2, "Must be defined as 'host:port'");
|
||||
nodes.add(new RedisNode(parts[0], Integer.valueOf(parts[1])));
|
||||
} catch (RuntimeException ex) {
|
||||
throw new IllegalStateException("Invalid redis sentinel " + "property '" + node + "'", ex);
|
||||
}
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
private JedisConnectionFactory createJedisConnectionFactory() {
|
||||
JedisPoolConfig poolConfig = this.properties.getPool() != null ? jedisPoolConfig() : new JedisPoolConfig();
|
||||
|
||||
if (getSentinelConfig() != null) {
|
||||
return new JedisConnectionFactory(getSentinelConfig(), poolConfig);
|
||||
}
|
||||
if (getClusterConfiguration() != null) {
|
||||
return new JedisConnectionFactory(getClusterConfiguration(), poolConfig);
|
||||
}
|
||||
return new JedisConnectionFactory(poolConfig);
|
||||
}
|
||||
|
||||
private JedisPoolConfig jedisPoolConfig() {
|
||||
JedisPoolConfig config = new JedisPoolConfig();
|
||||
RedisProperties.Pool props = this.properties.getPool();
|
||||
config.setMaxTotal(props.getMaxActive());
|
||||
config.setMaxIdle(props.getMaxIdle());
|
||||
config.setMinIdle(props.getMinIdle());
|
||||
config.setMaxWaitMillis(props.getMaxWait());
|
||||
return config;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Standard Redis configuration.
|
||||
*/
|
||||
@@ -468,5 +344,4 @@ public class MutiRedisAutoConfiguration {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import com.aliyun.oss.ClientConfiguration;
|
||||
import com.aliyun.oss.OSSClient;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -20,6 +21,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@Configuration
|
||||
@ConditionalOnClass({OSSClient.class})
|
||||
@EnableConfigurationProperties(OssProperties.class)
|
||||
@ConditionalOnProperty(name = "yexuejc.autoconfigure.oss.enable", matchIfMissing = false)
|
||||
public class OssAutoConfiguration {
|
||||
|
||||
private final OssProperties properties;
|
||||
|
@@ -63,4 +63,5 @@ public class OssProperties {
|
||||
this.bucket = bucket;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ import com.yexuejc.springboot.base.filter.ValidationFilterProperties;
|
||||
import com.yexuejc.springboot.base.interceptor.LogInterceptor;
|
||||
import com.yexuejc.springboot.base.util.LogUtil;
|
||||
import com.yexuejc.springboot.base.util.SSLUtil;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
@@ -52,6 +53,7 @@ import java.util.List;
|
||||
@Configuration
|
||||
@ConditionalOnWebApplication
|
||||
@EnableConfigurationProperties(ValidationFilterProperties.class)
|
||||
@ConditionalOnProperty(name = "yexuejc.autoconfigure.webmvc.enable", matchIfMissing = false)
|
||||
public class WebAutoConfiguration extends WebMvcConfigurerAdapter {
|
||||
|
||||
|
||||
@@ -61,6 +63,7 @@ public class WebAutoConfiguration extends WebMvcConfigurerAdapter {
|
||||
|
||||
/******************************************编码部分*****************************************************/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public HttpMessageConverter<String> responseBodyConverter() {
|
||||
StringHttpMessageConverter converter = new StringHttpMessageConverter(
|
||||
Charset.forName("UTF-8"));
|
||||
@@ -68,6 +71,7 @@ public class WebAutoConfiguration extends WebMvcConfigurerAdapter {
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
|
||||
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
|
||||
builder.serializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
@@ -120,6 +124,7 @@ public class WebAutoConfiguration extends WebMvcConfigurerAdapter {
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter(ObjectMapper objectMapper) {
|
||||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
|
||||
@@ -138,6 +143,7 @@ public class WebAutoConfiguration extends WebMvcConfigurerAdapter {
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnProperty(name = "yexuejc.web.validation-filter.enable", matchIfMissing = true)
|
||||
public FilterRegistrationBean validationFilter() {
|
||||
FilterRegistrationBean registration = new FilterRegistrationBean();
|
||||
@@ -148,11 +154,12 @@ public class WebAutoConfiguration extends WebMvcConfigurerAdapter {
|
||||
return registration;
|
||||
}
|
||||
|
||||
@Bean
|
||||
/**
|
||||
* 是否开启HTTPS(SSL)请求证书验证忽略:默认false
|
||||
*/
|
||||
@ConditionalOnProperty(name = "yexuejc.enable.ssl-ignore", matchIfMissing = false)
|
||||
@ConditionalOnProperty(name = "yexuejc.ssl-ignore.enable", matchIfMissing = false)
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public SSLUtil getSslUtil() {
|
||||
return new SSLUtil();
|
||||
}
|
||||
@@ -161,6 +168,7 @@ public class WebAutoConfiguration extends WebMvcConfigurerAdapter {
|
||||
* 全局异常处理
|
||||
*/
|
||||
@ControllerAdvice
|
||||
@ConditionalOnProperty(name = "yexuejc.global.exception.enable", matchIfMissing = true)
|
||||
static class GlobalExceptionHandler {
|
||||
private static final String ERROR_MSG = "系统错误,请联系管理员";
|
||||
|
||||
@@ -185,3 +193,5 @@ public class WebAutoConfiguration extends WebMvcConfigurerAdapter {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -9,6 +9,7 @@ import com.yexuejc.springboot.base.exception.GatewayException;
|
||||
import com.yexuejc.springboot.base.util.LogUtil;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -35,6 +36,7 @@ import java.security.interfaces.RSAPrivateKey;
|
||||
@ControllerAdvice
|
||||
@ConditionalOnClass({RequestBodyAdvice.class, HttpHeaders.class, HttpInputMessage.class, HttpMessageConverter.class})
|
||||
@EnableConfigurationProperties(RsaProperties.class)
|
||||
@ConditionalOnProperty(value = "yexuejc.filter.req.enable", matchIfMissing = false)
|
||||
public class ParamsRequestBodyAdvice implements RequestBodyAdvice {
|
||||
|
||||
private final RsaProperties properties;
|
||||
@@ -49,12 +51,25 @@ public class ParamsRequestBodyAdvice implements RequestBodyAdvice {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
|
||||
public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<?
|
||||
extends HttpMessageConverter<?>> converterType) {
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用入参加密
|
||||
* 自定义入参的解密方式只需要重写 beforeBodyRead 方法即可
|
||||
*
|
||||
* @param inputMessage
|
||||
* @param parameter
|
||||
* @param targetType
|
||||
* @param converterType
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) throws IOException {
|
||||
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<?
|
||||
extends HttpMessageConverter<?>> converterType) throws IOException {
|
||||
if (properties.isDecrypt()) {
|
||||
ParamsPO paramsPO = JsonUtil.json2Obj(IOUtils.toString(inputMessage.getBody(), "UTF-8"), ParamsPO.class);
|
||||
//RSA解密
|
||||
@@ -63,7 +78,8 @@ public class ParamsRequestBodyAdvice implements RequestBodyAdvice {
|
||||
RSAPrivateKey rsaPrivateKey = null;
|
||||
if (StrUtil.isEmpty(properties.getPrivateKey())) {
|
||||
rsaPrivateKey = RSA2.getPrivateKey(
|
||||
this.getClass().getResource(properties.getPrivateKeyPath()).getFile().toString(),
|
||||
// this.getClass().getResource(properties.getPrivateKeyPath()).getFile().toString(),
|
||||
this.getClass().getResourceAsStream(properties.getPrivateKeyPath()),
|
||||
properties.getPrivateAlias(),
|
||||
properties.getPrivatePwd());
|
||||
} else {
|
||||
@@ -92,7 +108,8 @@ public class ParamsRequestBodyAdvice implements RequestBodyAdvice {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
|
||||
public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<?
|
||||
extends HttpMessageConverter<?>> converterType) {
|
||||
return body;
|
||||
}
|
||||
|
||||
|
@@ -7,6 +7,7 @@ import com.yexuejc.base.util.JsonUtil;
|
||||
import com.yexuejc.base.util.StrUtil;
|
||||
import com.yexuejc.springboot.base.util.LogUtil;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -32,6 +33,7 @@ import java.util.Map;
|
||||
@ControllerAdvice
|
||||
@ConditionalOnClass({ResponseBodyAdvice.class, ServerHttpRequest.class, ServerHttpResponse.class, MediaType.class})
|
||||
@EnableConfigurationProperties(RsaProperties.class)
|
||||
@ConditionalOnProperty(value = "yexuejc.filter.resp.enable", matchIfMissing = false)
|
||||
public class ParamsResponseBodyAdvice implements ResponseBodyAdvice {
|
||||
|
||||
private final RsaProperties properties;
|
||||
@@ -47,7 +49,8 @@ public class ParamsResponseBodyAdvice implements ResponseBodyAdvice {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
|
||||
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class selectedConverterType,
|
||||
ServerHttpRequest request, ServerHttpResponse response) {
|
||||
if (returnType.getMethod().isAnnotationPresent(SerializedField.class)) {
|
||||
//获取注解配置的包含和去除字段
|
||||
SerializedField serializedField = returnType.getMethodAnnotation(SerializedField.class);
|
||||
@@ -74,7 +77,8 @@ public class ParamsResponseBodyAdvice implements ResponseBodyAdvice {
|
||||
RSAPrivateKey rsaPrivateKey = null;
|
||||
if (StrUtil.isEmpty(properties.getPrivateKey())) {
|
||||
rsaPrivateKey = RSA2.getPrivateKey(
|
||||
this.getClass().getResource(properties.getPrivateKeyPath()).getFile().toString(),
|
||||
// this.getClass().getResource(properties.getPrivateKeyPath()).getFile().toString(),
|
||||
this.getClass().getResourceAsStream(properties.getPrivateKeyPath()),
|
||||
properties.getPrivateAlias(),
|
||||
properties.getPrivatePwd());
|
||||
} else {
|
||||
|
@@ -5,28 +5,46 @@ spring.application.name=@pom.artifactId@
|
||||
logging.level.root=info
|
||||
logging.path=/logs/yexuejc-springboot-parent
|
||||
|
||||
|
||||
#========================================================================================================================
|
||||
#========================================================================================================================
|
||||
#核心
|
||||
#开启功能 redis webmvc
|
||||
yexuejc.autoconfigure.redis.enable=true
|
||||
#webmvc 包含以下功能
|
||||
yexuejc.autoconfigure.webmvc.enable=true
|
||||
#全局异常处理
|
||||
yexuejc.ssl-ignore.enable=true
|
||||
#开启HTTPS(SSL)请求证书验证忽略
|
||||
yexuejc.global.exception.enable=true
|
||||
#开启校验过滤器,目前校验HTTP Header是否符合规范
|
||||
yexuejc.web.validation-filter.enable=true
|
||||
# 拦截类型(请求路径):0忽略模式,默认拦截全部;1拦截模式,默认一个都不拦截
|
||||
#yexuejc.http.filter=0
|
||||
yexuejc.http.filter.type=1
|
||||
#忽略路径:示例放开swagger
|
||||
#yexuejc.http.filter.ignored=/,/swagger/**,/error,/v2/api-docs,/webjars/**
|
||||
#========================================================================================================================
|
||||
#========================================================================================================================
|
||||
|
||||
|
||||
yexuejc.http.encrypt.encrypt=true
|
||||
yexuejc.http.encrypt.decrypt=true
|
||||
#<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Կ<EFBFBD><EFBFBD>ʽ
|
||||
#配置密钥方式
|
||||
#yexuejc.http.encrypt.private-key=MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAiSo5blJ9-QJ0_QElcy5AaRTq-3oO4lJ8PvIOIt-Xr5SUFODVj3DUbiy6_0bxQYO3NiYHlXPb37UVV3jjlXJsXwIDAQABAkBE0WOJH2hGs93gRl_0vwLf9ffDfkTTdlER_73p70aad3QZRslEkinQH7G5aE_DgBm5m72TCeH-PD2FZ2lwtavBAiEAvnRown5Lpqbl0tN_OUxr_e1u9d_-8dNL_JEETO7BZCECIQC4XtY-18j0bVVLxaXPjKQ00D59yntwObihDNyRK0nAfwIgHPHEGgrnpGQo-Wl7JFIg925mNqfcLxRVsAS6CpcefQECIQCUsLdsmy6QIhTmNRJSXoSXq1KatE_05DhIekzwLs8eFQIgfMawMiu52ZxBI5_pZ7ancQZ6Dsxl45utFqJShzV1pio
|
||||
#yexuejc.http.encrypt.public-key=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAIkqOW5SffkCdP0BJXMuQGkU6vt6DuJSfD7yDiLfl6-UlBTg1Y9w1G4suv9G8UGDtzYmB5Vz29-1FVd445VybF8CAwEAAQ
|
||||
#<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD>鷽ʽ
|
||||
#配置证书方式
|
||||
yexuejc.http.encrypt.private-key-path=/lgfishing.keystore
|
||||
yexuejc.http.encrypt.private-alias=lgfishing
|
||||
yexuejc.http.encrypt.private-pwd=lgfishing2018
|
||||
|
||||
|
||||
#<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#编码
|
||||
spring.http.encoding.force=true
|
||||
spring.http.encoding.charset=UTF-8
|
||||
spring.http.encoding.enabled=true
|
||||
server.tomcat.uri-encoding=UTF-8
|
||||
|
||||
#<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>HTTPS<EFBFBD><EFBFBD>SSL<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD>Ĭ<EFBFBD><EFBFBD>false
|
||||
#是否开启HTTPS(SSL)请求证书验证忽略:默认false
|
||||
yexuejc.enable.ssl-ignore=true
|
||||
|
||||
|
||||
@@ -48,9 +66,9 @@ yexuejc.alibaba.oss.bucket=guansichou
|
||||
|
||||
|
||||
#========================================================================================================================
|
||||
# security<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
# security相关
|
||||
#reids
|
||||
#<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>redis<EFBFBD><EFBFBD>db0Ĭ<EFBFBD>Ͽ<EFBFBD><EFBFBD><EFBFBD>
|
||||
#开启指定redis库db0默认开启
|
||||
yexuejc.redis.db1=true
|
||||
spring.redis.jedis.pool.max-active=100
|
||||
spring.redis.jedis.pool.max-idle=10
|
||||
@@ -75,19 +93,19 @@ spring.datasource.data=classpath:db/data.sql
|
||||
#========================================================================================================================
|
||||
#mybatis-plus
|
||||
mybatis-plus.mapper-locations=classpath*:mapper/*.xml
|
||||
#ʵ<EFBFBD><EFBFBD>ɨ<EFBFBD>裬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>package<EFBFBD>ö<EFBFBD><EFBFBD>Ż<EFBFBD><EFBFBD>߷ֺŷָ<EFBFBD>
|
||||
#实体扫描,多个package用逗号或者分号分隔
|
||||
mybatis-plus.type-aliases-package=com.yexuejc.springboot.base.security.domain
|
||||
#<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0:"<22><><EFBFBD>ݿ<EFBFBD>ID<49><44><EFBFBD><EFBFBD>", 1:"<22>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>ID",2:"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊδ<CEAA><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 3:"ȫ<EFBFBD><EFBFBD>ΨһID UUID",4:ȫ<EFBFBD><EFBFBD>ΨһID (UUID),5:<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><EFBFBD>ΨһID (idWorker <EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ);
|
||||
#主键类型0:"数据库ID自增", 1:"用户输入ID",2:"该类型为未设置主键类型", 3:"全局唯一ID UUID",4:全局唯一ID (UUID),5:字符串全局唯一ID (idWorker 的字符串表示);
|
||||
mybatis-plus.global-config.db-config.id-type=uuid
|
||||
mybatis-plus.global-config.db-config.db-type=POSTGRE_SQL
|
||||
#<EFBFBD>ֶβ<EFBFBD><EFBFBD><EFBFBD> 0:"<22><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>",1:"<EFBFBD><EFBFBD> NULL <EFBFBD>ж<EFBFBD>"),2:"<EFBFBD>ǿ<EFBFBD><EFBFBD>ж<EFBFBD>"
|
||||
#字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
|
||||
mybatis-plus.global-config.db-config.field-strategy=not_empty
|
||||
#<EFBFBD>շ<EFBFBD><EFBFBD>»<EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD>
|
||||
#驼峰下划线转换
|
||||
mybatis-plus.global-config.db-config.column-underline=true
|
||||
#<EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>
|
||||
#逻辑删除配置(下面3个配置)
|
||||
mybatis-plus.global-config.db-config.logic-delete-value=true
|
||||
mybatis-plus.global-config.db-config.logic-not-delete-value=false
|
||||
#<EFBFBD><EFBFBD><EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>(column<6D>»<EFBFBD><C2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>&&<26><><EFBFBD><EFBFBD>javaʵ<61><CAB5><EFBFBD><EFBFBD><EFBFBD>շ<EFBFBD><D5B7><EFBFBD><EFBFBD><EFBFBD>)<29><><EFBFBD>Զ<EFBFBD>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>as<61><73>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SQL<51><4C>Ҫдas<61><73> select user_id as userId<EFBFBD><EFBFBD>
|
||||
#配置返回数据库(column下划线命名&&返回java实体是驼峰命名),自动匹配无需as(没开启这个,SQL需要写as: select user_id as userId)
|
||||
mybatis-plus.configuration.map-underscore-to-camel-case=true
|
||||
mybatis-plus.configuration.cache-enabled=false
|
||||
#========================================================================================================================
|
||||
|
Reference in New Issue
Block a user