mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2026-01-03 03:45:28 +08:00
JeecgBoot 2.1.1 代码生成器AI版本发布
This commit is contained in:
@ -20,6 +20,7 @@ public class MybatisPlusConfig {
|
||||
*/
|
||||
@Bean
|
||||
public PaginationInterceptor paginationInterceptor() {
|
||||
// 设置sql的limit为无限制,默认是500
|
||||
return new PaginationInterceptor().setLimit(-1);
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ import java.util.Arrays;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.jeecg.common.constant.CacheConstant;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
@ -36,28 +37,31 @@ public class RedisConfig extends CachingConfigurerSupport {
|
||||
@Resource
|
||||
private LettuceConnectionFactory lettuceConnectionFactory;
|
||||
|
||||
/**
|
||||
* @description 自定义的缓存key的生成策略 若想使用这个key
|
||||
* 只需要讲注解上keyGenerator的值设置为keyGenerator即可</br>
|
||||
* @return 自定义策略生成的key
|
||||
*/
|
||||
@Override
|
||||
@Bean
|
||||
public KeyGenerator keyGenerator() {
|
||||
return new KeyGenerator() {
|
||||
@Override
|
||||
public Object generate(Object target, Method method, Object... params) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(target.getClass().getName());
|
||||
sb.append(method.getDeclaringClass().getName());
|
||||
Arrays.stream(params).map(Object::toString).forEach(sb::append);
|
||||
return sb.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
// /**
|
||||
// * @description 自定义的缓存key的生成策略 若想使用这个key
|
||||
// * 只需要讲注解上keyGenerator的值设置为keyGenerator即可</br>
|
||||
// * @return 自定义策略生成的key
|
||||
// */
|
||||
// @Override
|
||||
// @Bean
|
||||
// public KeyGenerator keyGenerator() {
|
||||
// return new KeyGenerator() {
|
||||
// @Override
|
||||
// public Object generate(Object target, Method method, Object... params) {
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// sb.append(target.getClass().getName());
|
||||
// sb.append(method.getDeclaringClass().getName());
|
||||
// Arrays.stream(params).map(Object::toString).forEach(sb::append);
|
||||
// return sb.toString();
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
|
||||
/**
|
||||
* RedisTemplate配置
|
||||
*
|
||||
* @param lettuceConnectionFactory
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory lettuceConnectionFactory) {
|
||||
@ -81,11 +85,14 @@ public class RedisConfig extends CachingConfigurerSupport {
|
||||
|
||||
/**
|
||||
* 缓存配置管理器
|
||||
*
|
||||
* @param factory
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public CacheManager cacheManager(LettuceConnectionFactory factory) {
|
||||
// 配置序列化
|
||||
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofHours(1));
|
||||
// 配置序列化(缓存默认有效期 6小时)
|
||||
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofHours(6));
|
||||
RedisCacheConfiguration redisCacheConfiguration = config.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
|
||||
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer()));
|
||||
|
||||
@ -94,9 +101,9 @@ public class RedisConfig extends CachingConfigurerSupport {
|
||||
// 创建默认缓存配置对象
|
||||
/* 默认配置,设置缓存有效期 1小时*/
|
||||
//RedisCacheConfiguration defaultCacheConfig = RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofHours(1));
|
||||
/* 配置test的超时时间为120s*/
|
||||
/* 自定义配置test:demo 的超时时间为 5分钟*/
|
||||
RedisCacheManager cacheManager = RedisCacheManager.builder(RedisCacheWriter.lockingRedisCacheWriter(factory)).cacheDefaults(redisCacheConfiguration)
|
||||
.withInitialCacheConfigurations(singletonMap("test", RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofMinutes(120)).disableCachingNullValues()))
|
||||
.withInitialCacheConfigurations(singletonMap(CacheConstant.TEST_DEMO_CACHE, RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofMinutes(5)).disableCachingNullValues()))
|
||||
.transactionAware().build();
|
||||
return cacheManager;
|
||||
}
|
||||
|
||||
@ -1,11 +1,6 @@
|
||||
package org.jeecg.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.mgt.DefaultSessionStorageEvaluator;
|
||||
import org.apache.shiro.mgt.DefaultSubjectDAO;
|
||||
import org.apache.shiro.mgt.SecurityManager;
|
||||
@ -13,12 +8,22 @@ import org.apache.shiro.spring.LifecycleBeanPostProcessor;
|
||||
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
|
||||
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
|
||||
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
|
||||
import org.crazycake.shiro.RedisCacheManager;
|
||||
import org.crazycake.shiro.RedisManager;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.shiro.authc.ShiroRealm;
|
||||
import org.jeecg.modules.shiro.authc.aop.JwtFilter;
|
||||
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: Scott
|
||||
@ -26,9 +31,22 @@ import org.springframework.context.annotation.DependsOn;
|
||||
* @description: shiro 配置类
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class ShiroConfig {
|
||||
|
||||
|
||||
@Value("${jeecg.shiro.excludeUrls}")
|
||||
private String excludeUrls;
|
||||
|
||||
@Value("${spring.redis.port}")
|
||||
private String port;
|
||||
|
||||
@Value("${spring.redis.host}")
|
||||
private String host;
|
||||
|
||||
@Value("${spring.redis.password}")
|
||||
private String redisPassword;
|
||||
|
||||
/**
|
||||
* Filter Chain定义说明
|
||||
*
|
||||
@ -42,10 +60,18 @@ public class ShiroConfig {
|
||||
shiroFilterFactoryBean.setSecurityManager(securityManager);
|
||||
// 拦截器
|
||||
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
|
||||
if(oConvertUtils.isNotEmpty(excludeUrls)){
|
||||
String[] permissionUrl = excludeUrls.split(",");
|
||||
for(String url : permissionUrl){
|
||||
filterChainDefinitionMap.put(url,"anon");
|
||||
}
|
||||
}
|
||||
//cas验证登录
|
||||
filterChainDefinitionMap.put("/cas/client/validateLogin", "anon");
|
||||
// 配置不会被拦截的链接 顺序判断
|
||||
filterChainDefinitionMap.put("/sys/getCheckCode", "anon"); //登录验证码接口排除
|
||||
filterChainDefinitionMap.put("/sys/login", "anon"); //登录接口排除
|
||||
filterChainDefinitionMap.put("/sys/mLogin", "anon"); //登录接口排除
|
||||
filterChainDefinitionMap.put("/sys/logout", "anon"); //登出接口排除
|
||||
filterChainDefinitionMap.put("/sys/getEncryptedString", "anon"); //获取加密串
|
||||
filterChainDefinitionMap.put("/sys/sms", "anon");//短信验证码
|
||||
@ -87,19 +113,13 @@ public class ShiroConfig {
|
||||
filterChainDefinitionMap.put("/actuator/httptrace/**", "anon");
|
||||
filterChainDefinitionMap.put("/actuator/redis/**", "anon");
|
||||
|
||||
|
||||
filterChainDefinitionMap.put("/test/jeecgDemo/demo3", "anon"); //模板测试
|
||||
filterChainDefinitionMap.put("/test/jeecgDemo/redisDemo/**", "anon"); //redis测试
|
||||
//测试示例
|
||||
filterChainDefinitionMap.put("/test/jeecgDemo/html", "anon"); //模板页面
|
||||
filterChainDefinitionMap.put("/test/jeecgDemo/redis/**", "anon"); //redis测试
|
||||
|
||||
|
||||
|
||||
//排除Online请求
|
||||
filterChainDefinitionMap.put("/auto/cgform/**", "anon");
|
||||
//websocket排除
|
||||
filterChainDefinitionMap.put("/websocket/**", "anon");
|
||||
|
||||
|
||||
|
||||
|
||||
// 添加自己的过滤器并且取名为jwt
|
||||
Map<String, Filter> filterMap = new HashMap<String, Filter>(1);
|
||||
filterMap.put("jwt", new JwtFilter());
|
||||
@ -129,7 +149,8 @@ public class ShiroConfig {
|
||||
defaultSessionStorageEvaluator.setSessionStorageEnabled(false);
|
||||
subjectDAO.setSessionStorageEvaluator(defaultSessionStorageEvaluator);
|
||||
securityManager.setSubjectDAO(subjectDAO);
|
||||
|
||||
//自定义缓存实现,使用redis
|
||||
securityManager.setCacheManager(redisCacheManager());
|
||||
return securityManager;
|
||||
}
|
||||
|
||||
@ -146,7 +167,7 @@ public class ShiroConfig {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
|
||||
public static LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
|
||||
return new LifecycleBeanPostProcessor();
|
||||
}
|
||||
|
||||
@ -157,4 +178,38 @@ public class ShiroConfig {
|
||||
return advisor;
|
||||
}
|
||||
|
||||
/**
|
||||
* cacheManager 缓存 redis实现
|
||||
* 使用的是shiro-redis开源插件
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public RedisCacheManager redisCacheManager() {
|
||||
log.info("===============(1)创建缓存管理器RedisCacheManager");
|
||||
RedisCacheManager redisCacheManager = new RedisCacheManager();
|
||||
redisCacheManager.setRedisManager(redisManager());
|
||||
//redis中针对不同用户缓存(此处的id需要对应user实体中的id字段,用于唯一标识)
|
||||
redisCacheManager.setPrincipalIdFieldName("id");
|
||||
//用户权限信息缓存时间
|
||||
redisCacheManager.setExpire(200000);
|
||||
return redisCacheManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置shiro redisManager
|
||||
* 使用的是shiro-redis开源插件
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public RedisManager redisManager() {
|
||||
log.info("===============(2)创建RedisManager,连接Redis..URL= " + host + ":" + port);
|
||||
RedisManager redisManager = new RedisManager();
|
||||
redisManager.setHost(host + ":" + port);//老版本是分别setHost和setPort,新版本只需要setHost就可以了
|
||||
if (!StringUtils.isEmpty(redisPassword)) {
|
||||
redisManager.setPassword(redisPassword);
|
||||
}
|
||||
return redisManager;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package org.jeecg.config;
|
||||
|
||||
import org.jeecg.common.util.DySmsHelper;
|
||||
import org.jeecg.modules.message.handle.impl.EmailSendMsgHandle;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@ -17,9 +18,14 @@ public class StaticConfig {
|
||||
@Value("${jeecg.sms.accessKeySecret}")
|
||||
private String accessKeySecret;
|
||||
|
||||
@Value(value = "${spring.mail.username}")
|
||||
private String emailFrom;
|
||||
|
||||
|
||||
@Bean
|
||||
public void initStatic() {
|
||||
DySmsHelper.setAccessKeyId(accessKeyId);
|
||||
DySmsHelper.setAccessKeySecret(accessKeySecret);
|
||||
EmailSendMsgHandle.setEmailFrom(emailFrom);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
package org.jeecg.config.oss;
|
||||
|
||||
import org.jeecg.config.oss.OSSAutoConfiguration.OSSConfigurationImportSelector;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.ImportSelector;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
|
||||
/**
|
||||
* Object Storage Service auto configuration.
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(OSSProperties.class)
|
||||
@Import(OSSConfigurationImportSelector.class)
|
||||
public class OSSAutoConfiguration {
|
||||
|
||||
/**
|
||||
* {@link ImportSelector} to add {@link OSSType} configuration classes.
|
||||
*/
|
||||
static class OSSConfigurationImportSelector implements ImportSelector {
|
||||
|
||||
@Override
|
||||
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
|
||||
OSSType[] types = OSSType.values();
|
||||
String[] imports = new String[types.length];
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
imports[i] = OSSConfigurations.getConfigurationClass(types[i]);
|
||||
}
|
||||
return imports;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
package org.jeecg.config.oss;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
|
||||
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
|
||||
import org.springframework.boot.context.properties.bind.BindException;
|
||||
import org.springframework.boot.context.properties.bind.BindResult;
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
import org.springframework.context.annotation.ConditionContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.core.type.ClassMetadata;
|
||||
|
||||
/**
|
||||
* General OSS condition used with all OSS configuration classes.
|
||||
*/
|
||||
public class OSSCondition extends SpringBootCondition {
|
||||
|
||||
@Override
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
||||
String sourceClass = "";
|
||||
if (metadata instanceof ClassMetadata) {
|
||||
sourceClass = ((ClassMetadata) metadata).getClassName();
|
||||
}
|
||||
ConditionMessage.Builder message = ConditionMessage.forCondition("OSS", sourceClass);
|
||||
Environment environment = context.getEnvironment();
|
||||
try {
|
||||
BindResult<OSSType> specified = Binder.get(environment).bind("oss.type", OSSType.class);
|
||||
if (!specified.isBound()) {
|
||||
return ConditionOutcome.match(message.because("automatic OSS type"));
|
||||
}
|
||||
OSSType required = OSSConfigurations.getType(((AnnotationMetadata) metadata).getClassName());
|
||||
if (specified.get() == required) {
|
||||
return ConditionOutcome.match(message.because(specified.get() + " OSS type"));
|
||||
}
|
||||
}
|
||||
catch (BindException ex) {
|
||||
}
|
||||
return ConditionOutcome.noMatch(message.because("unknown OSS type"));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package org.jeecg.config.oss;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jeecg.config.oss.aliyun.AliYunOSSAutoConfiguration;
|
||||
import org.jeecg.config.oss.tencent.QcCOSAutoConfiguration;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
||||
/**
|
||||
* Mappings between {@link OSSType} and {@code @Configuration}.
|
||||
*/
|
||||
final class OSSConfigurations {
|
||||
|
||||
private static final Map<OSSType, Class<?>> MAPPINGS;
|
||||
|
||||
static {
|
||||
Map<OSSType, Class<?>> mappings = new EnumMap<>(OSSType.class);
|
||||
mappings.put(OSSType.ALIYUN, AliYunOSSAutoConfiguration.class);
|
||||
mappings.put(OSSType.QC, QcCOSAutoConfiguration.class);
|
||||
MAPPINGS = Collections.unmodifiableMap(mappings);
|
||||
}
|
||||
|
||||
private OSSConfigurations() {
|
||||
}
|
||||
|
||||
public static String getConfigurationClass(OSSType ossType) {
|
||||
Class<?> configurationClass = MAPPINGS.get(ossType);
|
||||
Assert.state(configurationClass != null, () -> "Unknown OSS type " + ossType);
|
||||
return configurationClass.getName();
|
||||
}
|
||||
|
||||
public static OSSType getType(String configurationClassName) {
|
||||
for (Map.Entry<OSSType, Class<?>> entry : MAPPINGS.entrySet()) {
|
||||
if (entry.getValue().getName().equals(configurationClassName)) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("Unknown configuration class " + configurationClassName);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package org.jeecg.config.oss;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* 简单上传,删除对象接口.
|
||||
* 可扩展
|
||||
*/
|
||||
public interface OSSManager {
|
||||
|
||||
void upload(String fileName, InputStream inputStream);
|
||||
|
||||
void delete(String fileName);
|
||||
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package org.jeecg.config.oss;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* Configuration properties for OSS support.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ConfigurationProperties(prefix = "jeecg.oss")
|
||||
public class OSSProperties {
|
||||
|
||||
/**
|
||||
* OSS type.
|
||||
*/
|
||||
private OSSType type;
|
||||
|
||||
/**
|
||||
* OSS Endpoint.
|
||||
*/
|
||||
private String endpoint;
|
||||
|
||||
/**
|
||||
* OSS Access key.
|
||||
*/
|
||||
private String accessKey;
|
||||
|
||||
/**
|
||||
* OSS Secret key.
|
||||
*/
|
||||
private String secretKey;
|
||||
|
||||
/**
|
||||
* OSS Bucket Name.
|
||||
*/
|
||||
private String bucketName;
|
||||
|
||||
/**
|
||||
* Additional OSS properties.
|
||||
*/
|
||||
private Map<String, String> properties = new HashMap<>();
|
||||
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package org.jeecg.config.oss;
|
||||
|
||||
/**
|
||||
* Supported OSS types.
|
||||
*/
|
||||
public enum OSSType {
|
||||
|
||||
ALIYUN, QC
|
||||
|
||||
}
|
||||
@ -0,0 +1,81 @@
|
||||
package org.jeecg.config.oss.aliyun;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.aliyun.oss.ClientBuilderConfiguration;
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.aliyun.oss.common.comm.Protocol;
|
||||
import org.jeecg.config.oss.OSSCondition;
|
||||
import org.jeecg.config.oss.OSSManager;
|
||||
import org.jeecg.config.oss.OSSProperties;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Conditional;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* AliYun OSS configuration.
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({ OSS.class })
|
||||
@ConditionalOnProperty(prefix = "jeecg.oss", name = "type",havingValue = "aliyun")
|
||||
@Conditional(OSSCondition.class)
|
||||
public class AliYunOSSAutoConfiguration {
|
||||
|
||||
private final OSSProperties properties;
|
||||
|
||||
public AliYunOSSAutoConfiguration(OSSProperties ossProperties) {
|
||||
this.properties = ossProperties;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ClientBuilderConfiguration clientConfiguration(OSSProperties ossProperties) {
|
||||
Properties properties = asProperties(ossProperties.getProperties());
|
||||
ClientBuilderConfiguration configuration = new ClientBuilderConfiguration();
|
||||
configuration.setMaxConnections(Integer.parseInt(properties.getProperty("aliyun.maxConnections", "5")));
|
||||
configuration.setSocketTimeout(Integer.parseInt(properties.getProperty("aliyun.socketTimeout", "50000")));
|
||||
configuration
|
||||
.setConnectionTimeout(Integer.parseInt(properties.getProperty("aliyun.connectionTimeout", "50000")));
|
||||
configuration.setConnectionRequestTimeout(
|
||||
Integer.parseInt(properties.getProperty("aliyun.connectionRequestTimeout", "-1")));
|
||||
configuration
|
||||
.setIdleConnectionTime(Integer.parseInt(properties.getProperty("aliyun.idleConnectionTime", "60000")));
|
||||
configuration.setMaxErrorRetry(Integer.parseInt(properties.getProperty("aliyun.maxErrorRetry", "3")));
|
||||
configuration.setSupportCname(Boolean.parseBoolean(properties.getProperty("aliyun.supportCname", "false")));
|
||||
configuration.setSLDEnabled(Boolean.parseBoolean(properties.getProperty("aliyun.sldEnabled", "false")));
|
||||
configuration.setProtocol(Protocol.HTTP);
|
||||
if (Protocol.HTTPS.toString().equals(properties.getProperty("aliyun.protocol"))) {
|
||||
configuration.setProtocol(Protocol.HTTPS);
|
||||
}
|
||||
if (properties.getProperty("aliyun.userAgent") != null) {
|
||||
configuration.setUserAgent(properties.getProperty("aliyun.userAgent"));
|
||||
}
|
||||
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Bean(destroyMethod = "shutdown")
|
||||
@ConditionalOnMissingBean
|
||||
public OSS ossClient(ClientBuilderConfiguration clientConfiguration) {
|
||||
return new OSSClientBuilder().build(this.properties.getEndpoint(), this.properties.getAccessKey(),
|
||||
this.properties.getSecretKey(), clientConfiguration);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public OSSManager ossManager(OSS ossClient) {
|
||||
return new AliYunOSSManager(ossClient, this.properties);
|
||||
}
|
||||
|
||||
private Properties asProperties(Map<String, String> source) {
|
||||
Properties properties = new Properties();
|
||||
properties.putAll(source);
|
||||
return properties;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package org.jeecg.config.oss.aliyun;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.aliyun.oss.OSS;
|
||||
import org.jeecg.config.oss.OSSManager;
|
||||
import org.jeecg.config.oss.OSSProperties;
|
||||
|
||||
/**
|
||||
* Object Storage Service of AliYun.
|
||||
*/
|
||||
public class AliYunOSSManager implements OSSManager {
|
||||
|
||||
private OSS client;
|
||||
|
||||
private OSSProperties properties;
|
||||
|
||||
AliYunOSSManager(OSS client, OSSProperties properties) {
|
||||
this.client = client;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upload(String fileName, InputStream inputStream) {
|
||||
this.client.putObject(this.properties.getBucketName(), fileName, inputStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String fileName) {
|
||||
this.client.deleteObject(this.properties.getBucketName(), fileName);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
package org.jeecg.config.oss.tencent;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.qcloud.cos.COS;
|
||||
import com.qcloud.cos.COSClient;
|
||||
import com.qcloud.cos.ClientConfig;
|
||||
import com.qcloud.cos.auth.BasicCOSCredentials;
|
||||
import com.qcloud.cos.auth.COSCredentials;
|
||||
import com.qcloud.cos.region.Region;
|
||||
import org.jeecg.config.oss.OSSCondition;
|
||||
import org.jeecg.config.oss.OSSManager;
|
||||
import org.jeecg.config.oss.OSSProperties;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Conditional;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass({ COS.class })
|
||||
@ConditionalOnProperty(prefix = "jeecg.oss", name = "type",havingValue = "qc")
|
||||
@Conditional(OSSCondition.class)
|
||||
public class QcCOSAutoConfiguration {
|
||||
|
||||
private final OSSProperties properties;
|
||||
|
||||
public QcCOSAutoConfiguration(OSSProperties ossProperties) {
|
||||
this.properties = ossProperties;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ClientConfig clientConfiguration(OSSProperties ossProperties) {
|
||||
Properties properties = asProperties(ossProperties.getProperties());
|
||||
ClientConfig configuration = new ClientConfig();
|
||||
configuration.setMaxConnectionsCount(Integer.parseInt(properties.getProperty("qc.maxConnectionsCount", "5")));
|
||||
configuration.setSocketTimeout(Integer.parseInt(properties.getProperty("qc.socketTimeout", "50000")));
|
||||
configuration.setConnectionTimeout(Integer.parseInt(properties.getProperty("qc.connectionTimeout", "50000")));
|
||||
configuration.setConnectionRequestTimeout(
|
||||
Integer.parseInt(properties.getProperty("qc.connectionRequestTimeout", "-1")));
|
||||
configuration.setRegion(new Region(properties.getProperty("qc.region")));
|
||||
if (properties.getProperty("qc.userAgent") != null) {
|
||||
configuration.setUserAgent(properties.getProperty("qc.userAgent"));
|
||||
}
|
||||
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Bean(destroyMethod = "shutdown")
|
||||
@ConditionalOnMissingBean
|
||||
public COS ossClient(ClientConfig clientConfig) {
|
||||
COSCredentials cred = new BasicCOSCredentials(this.properties.getAccessKey(), this.properties.getSecretKey());
|
||||
return new COSClient(cred, clientConfig);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public OSSManager ossManager(COS client) {
|
||||
return new QcCOSManager(client, this.properties);
|
||||
}
|
||||
|
||||
private Properties asProperties(Map<String, String> source) {
|
||||
Properties properties = new Properties();
|
||||
properties.putAll(source);
|
||||
return properties;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package org.jeecg.config.oss.tencent;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.qcloud.cos.COS;
|
||||
import com.qcloud.cos.model.ObjectMetadata;
|
||||
import org.jeecg.config.oss.OSSManager;
|
||||
import org.jeecg.config.oss.OSSProperties;
|
||||
|
||||
/**
|
||||
* Object Storage Service of Tencent cloud.
|
||||
*/
|
||||
public class QcCOSManager implements OSSManager {
|
||||
|
||||
private COS client;
|
||||
|
||||
private OSSProperties properties;
|
||||
|
||||
QcCOSManager(COS client, OSSProperties properties) {
|
||||
this.client = client;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upload(String fileName, InputStream inputStream) {
|
||||
ObjectMetadata objectMetadata = new ObjectMetadata();
|
||||
objectMetadata.setContentLength(10);
|
||||
objectMetadata.setContentType("application/octet-stream");
|
||||
this.client.putObject(this.properties.getBucketName(),
|
||||
this.properties.getProperties().get("qc.prefix") + "/" + fileName, inputStream, objectMetadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String fileName) {
|
||||
this.client.deleteObject(this.properties.getBucketName(),
|
||||
this.properties.getProperties().get("qc.prefix") + "/" + fileName);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user