org.zodiac.autoconfigure.template.velocity.VelocityTemplateAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.template.velocity;
import javax.annotation.Resource;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ResourceLoader;
import org.zodiac.autoconfigure.application.ApplicationInfoProperties;
import org.zodiac.autoconfigure.template.velocity.condition.ConditionalOnVelocityTemplateEnabled;
@SpringBootConfiguration
//@EnableConfigurationProperties(value = {VelocityViewProperties.class})
@ConditionalOnVelocityTemplateEnabled
@ConditionalOnClass(value = {org.apache.velocity.app.VelocityEngine.class, org.zodiac.template.velocity.impl.VelocityRuntimeInstance.class})
public class VelocityTemplateAutoConfiguration {
private final ResourceLoader resourceLoader;
@Resource
private VelocityTemplatePriperties velocityTemplatePriperties;
public VelocityTemplateAutoConfiguration(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}
@Bean
@ConditionalOnMissingBean
@ConfigurationProperties(prefix = org.zodiac.template.velocity.constants.VelocityTemplateSystemPropertiesConstants.SPRING_TEMPLATE_VELOCITY_PREFIX, ignoreInvalidFields = true)
protected VelocityTemplatePriperties velocityTemplatePriperties(ApplicationInfoProperties applicationInfoProperties) {
return new VelocityTemplatePriperties().setAppEnvType(applicationInfoProperties.envType());
}
@Bean
@ConditionalOnMissingBean(value = {org.zodiac.template.velocity.VelocityTemplateEngine.class})
protected org.zodiac.template.velocity.VelocityTemplateEngine velocityTemplateEngine(VelocityTemplatePriperties velocityTemplatePriperties) {
org.zodiac.template.velocity.impl.VelocityTemplateEngineImpl engine = new org.zodiac.template.velocity.impl.VelocityTemplateEngineImpl();
engine.setAdvancedProperties(velocityTemplatePriperties.getProperties())
.setCacheEnabled(velocityTemplatePriperties.getCacheEnabled())
.setGlobalMacros(velocityTemplatePriperties.getMacros())
.setModificationCheckInterval(velocityTemplatePriperties.getModificationCheckSeconds())
.setPath(velocityTemplatePriperties.getPath())
.setPlugins(velocityTemplatePriperties.getPlugins())
.setStrictReference(velocityTemplatePriperties.isStrictReference())
.setTemplateEncoding(velocityTemplatePriperties.getCharset())
.setParserPoolSize(velocityTemplatePriperties.getParserPoolSize())
.setExceptionWrongArgs(velocityTemplatePriperties.isExceptionWrongArgs())
.setLogWhenFoundTemplate(velocityTemplatePriperties.isLogWhenFoundTemplate())
.setInlineLocalScope(velocityTemplatePriperties.isInlineLocalScope())
.addPreloadedResources(velocityTemplatePriperties.getPreloadedResources());
engine.setProductionMode(velocityTemplatePriperties.isProductionMode());
engine.setResourceLoader(this.resourceLoader);
return engine;
}
}