
org.kaizen4j.starter.view.velocity.VelocityAutoConfiguration Maven / Gradle / Ivy
package org.kaizen4j.starter.view.velocity;
import org.kaizen4j.integration.spring.view.velocity.VelocityConfigurer;
import org.kaizen4j.integration.spring.view.velocity.VelocityLayoutView;
import org.kaizen4j.integration.spring.view.velocity.VelocityLayoutViewResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.Properties;
@Configuration
@EnableConfigurationProperties({VelocityProperties.class})
@ConditionalOnProperty(prefix = "ka4j.velocity", value = "enabled", havingValue = "true")
public class VelocityAutoConfiguration implements WebMvcConfigurer {
private static final Logger logger = LoggerFactory.getLogger(VelocityAutoConfiguration.class);
private VelocityProperties velocityProperties;
public VelocityAutoConfiguration(VelocityProperties velocityProperties) {
this.velocityProperties = velocityProperties;
}
@Bean
public VelocityConfigurer velocityConfigurer() {
VelocityConfigurer velocityConfigurer = new VelocityConfigurer();
velocityConfigurer.setResourceLoaderPath(velocityProperties.getResourceLoaderPath());
Properties properties = new Properties();
velocityProperties.getProps().forEach(config -> properties.put(config.getName(), config.getValue()));
velocityConfigurer.setVelocityProperties(properties);
logger.info("Kaizen4j 自动配置 Velocity 创建 [VelocityConfigurer] 完成");
return velocityConfigurer;
}
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
VelocityLayoutViewResolver viewResolver = new VelocityLayoutViewResolver();
viewResolver.setCache(true);
viewResolver.setPrefix(velocityProperties.getPrefix());
viewResolver.setSuffix(velocityProperties.getSuffix());
viewResolver.setContentType(velocityProperties.getContentType());
viewResolver.setLayoutUrl(velocityProperties.getLayoutUrl());
viewResolver.setExposeRequestAttributes(true);
viewResolver.setExposeSessionAttributes(true);
viewResolver.setAllowRequestOverride(false);
viewResolver.setAllowSessionOverride(false);
viewResolver.setToolboxConfigLocation(velocityProperties.getToolboxConfigLocation());
viewResolver.setViewClass(VelocityLayoutView.class);
logger.info("Kaizen4j 自动配置 Velocity 创建 [VelocityLayoutViewResolver] 完成");
registry.viewResolver(viewResolver);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy