功能插件装配开关

This commit is contained in:
yexuejc 2019-07-27 09:27:32 +08:00
parent 83a20b010b
commit b93672f52f
12 changed files with 142 additions and 16 deletions

View File

@ -13,7 +13,7 @@ base:功能封装
#### 最新版本
>yexuejc.springboot.version=2.0.5 <br>
>yexuejc.base.version=1.2.4
>yexuejc.base.version=1.3.9
pom.xml
```

View File

@ -1,6 +1,19 @@
yexuejc-springboot 更新内容
-------------------
#### version 2.1.0
**time2019-7-24 18:30:49** <br/>
**branch** master <br/>
**关联工程:** <br/>
```
springboot-base:1.3.9
spring-boot-starter-parent:2.0.5.RELEASE
```
**update** <br/>
1. 所有自动装配增加开关,默认不装配。装配方式请参考[本项目自动装配开关](doc/plugin/AutoConfigure.md)
#
#### version 2.0.6
**time2019年4月2日21:08:453** <br/>
**branch** master <br/>

View File

@ -1,7 +1,7 @@
功能目录
------------------------
### 第三方集成
### 第三方集成 -> [第三方集成具体使用](plugin/AutoConfigure.md)
#
* [redis 集成](REDIS.md)
* [Aliyun MNS 消息队列](MNS.md)

View File

@ -4,19 +4,19 @@ keytool -genkey -alias lgfishing -keyalg RSA -keystore lgfishing2.keystore -keys
输入密钥库口令:
再次输入新口令:
您的名字与姓氏是什么?
[Unknown]: heikengdiaoyu.com
[Unknown]: 1107047387@qq.com
您的组织单位名称是什么?
[Unknown]: 深圳金大米网络科技有限公司-老G钓鱼
[Unknown]: yexuejc
您的组织名称是什么?
[Unknown]: 成都极致思维网络科技有限公司-老G钓鱼
[Unknown]: 成都极致思维网络科技有限公司
您所在的城市或区域名称是什么?
[Unknown]: 成都
您所在的省/市/自治区名称是什么?
[Unknown]: 四川
该单位的双字母国家/地区代码是什么?
[Unknown]: CN
CN=heikengdiaoyu.com, OU=深圳金大米网络科技有限公司-老G钓鱼, O=成都极致思维网络科技有限公司-老G钓鱼, L=成都, ST=四川, C=CN是否正确?
CN=1107047387@qq.com, OU=yexuejc, O=成都极致思维网络科技有限公司, L=成都, ST=四川, C=CN是否正确?
[否]: 是
```
#生成公钥
keytool -export -alias lgfishing -keystore lgfishing2.keystore -storepass lgfishing2018 -rfc -file lgfishing2.cer
keytool -export -alias test -keystore test.keystore -storepass test2018 -rfc -file test2018.cer

View File

@ -0,0 +1,95 @@
本项目自动装配开关
---------------------
## 说明
本项目从2.1.0开始所有自动装配的功能增加开关控制,默认插件功能关闭.
开启需要在使用项目`application.properties`中增加`yexuejc.autoconfigure.mns.enable=true`类似的配置每一个插件功能key不一样
### 插件功能
注:使用阿里系的功能请引入阿里基础包
```
<!-- 阿里云基础SDK -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<optional>true</optional>
</dependency>
```
#### 阿里云MNS功能
> 类:[MnsAutoConfiguration](../../yexuejc-springboot-base/src/main/java/com/yexuejc/springboot/base/autoconfigure/MnsAutoConfiguration.java)
> <br/> 功能开关:`yexuejc.autoconfigure.mns.enable=true`
> <br/> 依赖:`MNSClient.class`
> <br/> pom 引入
> ```
> <!-- 阿里云消息服务MNS相关SDK -->
> <dependency>
> <groupId>com.aliyun.mns</groupId>
> <artifactId>aliyun-sdk-mns</artifactId>
> <classifier>jar-with-dependencies</classifier>
> <optional>true</optional>
> </dependency>
> ```
>application.properties 配置
>```
> yexuejc.alibaba.mns.access-key-id=自己到阿里云申请access-key
> yexuejc.alibaba.mns.access-key-secret=自己到阿里云申请access-key-secret
> yexuejc.alibaba.mns.endpoint=自己阿里云的endpoint
> yexuejc.alibaba.mns.queue-name-prefix=mns前缀
>```
#### redis 多database 配置
> 类:[MutiRedisAutoConfiguration](../../yexuejc-springboot-base/src/main/java/com/yexuejc/springboot/base/autoconfigure/MutiRedisAutoConfiguration.java)
> <br/> 功能开关:`yexuejc.autoconfigure.redis.enable=true`
> <br/> 依赖:`JedisConnection.class`, `RedisOperations.class`, `Jedis.class`
> <br/> pom 引入
> ```
> <!-- 使用Redis -->
> <dependency>
> <groupId>org.springframework.data</groupId>
> <artifactId>spring-data-redis</artifactId>
> <optional>true</optional>
> </dependency>
> <dependency>
> <groupId>redis.clients</groupId>
> <artifactId>jedis</artifactId>
> <optional>true</optional>
> </dependency>
> ```
>application.properties 配置
><br/> 默认db0k开启 1-15需要使用哪个`yexuejc.redis.dbx=true`
>```
> yexuejc.redis.db1=true
> spring.redis.jedis.pool.max-active=100
> spring.redis.jedis.pool.max-idle=10
> spring.redis.jedis.pool.min-idle=3
> spring.redis.host=地址
> spring.redis.password=密码
> spring.redis.port=端口
>```
#### 阿里 OSS 功能
> 类:[OssAutoConfiguration](../../yexuejc-springboot-base/src/main/java/com/yexuejc/springboot/base/autoconfigure/OssAutoConfiguration.java)
> <br/> 功能开关:`yexuejc.autoconfigure.oss.enable=true`
> <br/> 依赖:`OSSClient`
> <br/> pom 引入
> ```
> <!-- 阿里云OSS相关SDK -->
> <dependency>
> <groupId>com.aliyun.oss</groupId>
> <artifactId>aliyun-sdk-oss</artifactId>
> <optional>true</optional>
> </dependency>
> ```
>application.properties 配置
>```
> yexuejc.alibaba.oss.endpoint=自己去阿里申请的endpoint
> yexuejc.alibaba.oss.access-key-secret=自己到阿里云申请access-key-secret
> yexuejc.alibaba.oss.access-key-id=自己到阿里云申请access-key
> yexuejc.alibaba.oss.bucket=自己去阿里申请的bucket
>```
#### WebMvc 相关配置
> 类:[WebAutoConfiguration](../../yexuejc-springboot-base/src/main/java/com/yexuejc/springboot/base/autoconfigure/WebAutoConfiguration.java)
> <br/> 功能开关:`yexuejc.autoconfigure.webmvc.enable=true`
> 本类开启后的具体使用说明参见[WebMvc相关配置](WebAutoConfiguration.md)

View File

@ -0,0 +1,2 @@
WebMvc相关配置 [WebAutoConfiguration](../../yexuejc-springboot-base/src/main/java/com/yexuejc/springboot/base/autoconfigure/WebAutoConfiguration.java)
------------------------------------

10
pom.xml
View File

@ -5,7 +5,7 @@
<groupId>com.yexuejc.springboot</groupId>
<artifactId>yexuejc-springboot-parent</artifactId>
<version>2.0.6</version>
<version>2.1.0</version>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
@ -20,6 +20,11 @@
<!--lookup parent from repository-->
</parent>
<modules>
<module>yexuejc-springboot-base</module>
</modules>
<properties>
<yexuejc.base.version>1.3.9</yexuejc.base.version>
<repos.yexuejc.url>https://nexus.yexuejc.club/repository/</repos.yexuejc.url>
@ -305,7 +310,4 @@
</snapshotRepository>
</distributionManagement>
<modules>
<module>yexuejc-springboot-base</module>
</modules>
</project>

View File

@ -9,7 +9,7 @@
<parent>
<groupId>com.yexuejc.springboot</groupId>
<artifactId>yexuejc-springboot-parent</artifactId>
<version>2.0.6</version>
<version>2.1.0</version>
<!-- 本地打包:使用相对关联路径 -->
<!--<relativePath>../</relativePath>-->
</parent>

View File

@ -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;

View File

@ -37,6 +37,7 @@ import java.net.UnknownHostException;
@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";

View File

@ -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;

View File

@ -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
/**
* 是否开启HTTPSSSL请求证书验证忽略默认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 {
}
}