com.spring.boxes.mutant.MutantAutoConfiguration Maven / Gradle / Ivy
package com.spring.boxes.mutant;
import com.googlecode.aviator.AviatorEvaluator;
import com.googlecode.aviator.spring.SpringContextFunctionLoader;
import com.spring.boxes.dollar.support.aviator.AviatorFunction;
import com.spring.boxes.dollar.support.mutant.resolver.type.DefaultResolver;
import com.spring.boxes.dollar.support.mutant.resolver.type.MixupResolver;
import com.spring.boxes.dollar.support.mutant.resolver.type.Mvel2Resolver;
import com.spring.boxes.dollar.support.mutant.resolver.type.PathAviResolver;
import com.spring.boxes.dollar.support.thread.BoxesThreadPoolCreate;
import com.spring.boxes.mutant.options.GatewayCacheOptions;
import com.spring.boxes.mutant.configure.MutantThreadPoolProperties;
import com.spring.boxes.mutant.resolver.ResolverTemplate;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import java.util.concurrent.ExecutorService;
@Data
@Slf4j
@Configuration
@EnableConfigurationProperties({MutantThreadPoolProperties.class})
public class MutantAutoConfiguration {
@Autowired
private ApplicationContext applicationContext;
@Autowired
private StringRedisTemplate stringRedisTemplate;
@Autowired
private MutantThreadPoolProperties mutantThreadPoolProperties;
@Bean
public SpringContextFunctionLoader springContextFunctionLoader(){
SpringContextFunctionLoader springContextFunctionLoader = new SpringContextFunctionLoader(applicationContext);
AviatorEvaluator.addFunctionLoader(springContextFunctionLoader);
try {
AviatorEvaluator.addStaticFunctions("mutant", AviatorFunction.class);
AviatorEvaluator.addStaticFunctions("stringUtils", StringUtils.class);
AviatorEvaluator.addStaticFunctions("numberUtils", NumberUtils.class);
AviatorEvaluator.addStaticFunctions("dateFormatUtils", DateFormatUtils.class);
AviatorEvaluator.addStaticFunctions("dateUtils", DateUtils.class);
AviatorEvaluator.addStaticFunctions("arrayUtils", ArrayUtils.class);
AviatorEvaluator.addStaticFunctions("collectionUtils", CollectionUtils.class);
} catch (Exception e) {
log.error(e.getLocalizedMessage(), e);
}
return springContextFunctionLoader;
}
@Bean
@ConditionalOnMissingBean
public DefaultResolver defaultResolver(){
return new DefaultResolver();
}
@Bean
@ConditionalOnMissingBean
public MixupResolver mixupResolver(){
MixupResolver mixupResolver = new MixupResolver();
mixupResolver.setExecutorService(mutantExecutorService());
return mixupResolver;
}
@Bean
@ConditionalOnMissingBean
public Mvel2Resolver mvel2Resolver(){
return new Mvel2Resolver();
}
@Bean
@ConditionalOnMissingBean
public PathAviResolver pathAviResolver(){
return new PathAviResolver();
}
@Bean
@ConditionalOnMissingBean
public ResolverTemplate resolverTemplate(){
return new ResolverTemplate(gatewayOptions(), applicationContext);
}
@Bean
@ConditionalOnMissingBean
public GatewayCacheOptions gatewayOptions(){
return GatewayCacheOptions.newInstance(stringRedisTemplate);
}
@Bean(name = "mutantExecutorService")
public ExecutorService mutantExecutorService() {
return BoxesThreadPoolCreate.create(this.mutantThreadPoolProperties).getExecutorService();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy