Commit ab03d056 by fsn

重新整理beetl配置

parent 6e647ca5
package com.stylefeng.guns.config.properties;
import com.stylefeng.guns.core.util.ToolUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import java.util.Properties;
/**
* beetl配置
* beetl配置(如果需要配置别的配置可参照这个形式自己添加)
*
* @author fengshuonan
* @date 2017-05-22 18:45
* @date 2017-05-24 20:37
*/
@Configuration
@ConfigurationProperties(prefix = BeetlProperties.BEETLCONF_PREFIX)
public class BeetlProperties {
private static BeetlProperties beetlProperties = new BeetlProperties();
public static final String BEETLCONF_PREFIX = "beetl";
private String delimiterStatementStart;
private String delimiterStatementEnd;
private String resourceTagroot;
private String resourceTagsuffix;
@Value("${spring.mvc.view.prefix}")
private String prefix;
public Properties getProperties(){
Properties properties = new Properties();
if(ToolUtil.isNotEmpty(delimiterStatementStart)){
if(delimiterStatementStart.startsWith("\\")){
delimiterStatementStart = delimiterStatementStart.substring(1);
}
properties.setProperty("DELIMITER_STATEMENT_START",delimiterStatementStart);
}
if(ToolUtil.isNotEmpty(delimiterStatementEnd)){
properties.setProperty("DELIMITER_STATEMENT_END",delimiterStatementEnd);
}else{
properties.setProperty("DELIMITER_STATEMENT_END","null");
}
if(ToolUtil.isNotEmpty(resourceTagroot)){
properties.setProperty("RESOURCE.tagRoot",resourceTagroot);
}
if(ToolUtil.isNotEmpty(resourceTagsuffix)){
properties.setProperty("RESOURCE.tagSuffix",resourceTagsuffix);
}
return properties;
}
private Properties properties = new Properties();
public String getPrefix() {
return prefix;
}
private BeetlProperties(){
init();
public String getDelimiterStatementStart() {
return delimiterStatementStart;
}
public void init() {
//开始结束占位符
this.properties.setProperty("DELIMITER_PLACEHOLDER_START", "${");
this.properties.setProperty("DELIMITER_PLACEHOLDER_END", "}");
public void setDelimiterStatementStart(String delimiterStatementStart) {
this.delimiterStatementStart = delimiterStatementStart;
}
//开始结束标签
this.properties.setProperty("DELIMITER_STATEMENT_START", "@");
this.properties.setProperty("DELIMITER_STATEMENT_END", "null");
public String getDelimiterStatementEnd() {
return delimiterStatementEnd;
}
//classpath 根路径
this.properties.setProperty("RESOURCE.root", "/");
public void setDelimiterStatementEnd(String delimiterStatementEnd) {
this.delimiterStatementEnd = delimiterStatementEnd;
}
//是否检测文件变化
this.properties.setProperty("RESOURCE.autoCheck", "true");
public String getResourceTagroot() {
return resourceTagroot;
}
//beetl HTMl标签
this.properties.setProperty("HTML_TAG_FLAG", "#");
public void setResourceTagroot(String resourceTagroot) {
this.resourceTagroot = resourceTagroot;
}
//自定义标签文件Root目录和后缀
this.properties.setProperty("RESOURCE.tagRoot", "common/tags");
this.properties.setProperty("RESOURCE.tagSuffix", "tag");
public String getResourceTagsuffix() {
return resourceTagsuffix;
}
public static Properties newInstance(){
return beetlProperties.properties;
public void setResourceTagsuffix(String resourceTagsuffix) {
this.resourceTagsuffix = resourceTagsuffix;
}
}
package com.stylefeng.guns.config.web;
import com.stylefeng.guns.config.properties.BeetlProperties;
import com.stylefeng.guns.core.beetl.BeetlConfiguration;
import org.beetl.core.resource.ClasspathResourceLoader;
import org.beetl.ext.spring.BeetlSpringViewResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* web 配置类
*
* @author fengshuonan
* @date 2016年11月12日 下午5:03:32
*/
@Configuration
@ConfigurationProperties(prefix = "spring.mvc.view")
public class BeetlConfig {
@Autowired
BeetlProperties beetlProperties;
/**
* beetl的配置
*/
@Bean(initMethod = "init")
public BeetlConfiguration beetlConfiguration() {
BeetlConfiguration beetlConfiguration = new BeetlConfiguration();
beetlConfiguration.setResourceLoader(new ClasspathResourceLoader(BeetlConfig.class.getClassLoader(), beetlProperties.getPrefix()));
beetlConfiguration.setConfigProperties(beetlProperties.getProperties());
return beetlConfiguration;
}
/**
* beetl的视图解析器
*/
@Bean
public BeetlSpringViewResolver beetlViewResolver() {
BeetlSpringViewResolver beetlSpringViewResolver = new BeetlSpringViewResolver();
beetlSpringViewResolver.setConfig(beetlConfiguration());
beetlSpringViewResolver.setContentType("text/html;charset=UTF-8");
beetlSpringViewResolver.setOrder(0);
return beetlSpringViewResolver;
}
}
package com.stylefeng.guns.config.web;
import com.alibaba.druid.support.http.StatViewServlet;
import com.stylefeng.guns.config.properties.BeetlProperties;
import com.stylefeng.guns.core.beetl.BeetlConfiguration;
import com.stylefeng.guns.core.listener.ConfigListener;
import com.stylefeng.guns.core.util.xss.XssFilter;
import org.beetl.core.resource.ClasspathResourceLoader;
import org.beetl.ext.spring.BeetlSpringViewResolver;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
......@@ -22,35 +17,8 @@ import org.springframework.web.context.request.RequestContextListener;
* @date 2016年11月12日 下午5:03:32
*/
@Configuration
@ConfigurationProperties(prefix = "spring.mvc.view")
public class WebConfig {
//beetl模板所放的地方
private String prefix;
/**
* beetl的配置
*/
@Bean(initMethod = "init")
public BeetlConfiguration beetlConfiguration() {
BeetlConfiguration beetlConfiguration = new BeetlConfiguration();
beetlConfiguration.setResourceLoader(new ClasspathResourceLoader(WebConfig.class.getClassLoader(), prefix));
beetlConfiguration.setConfigProperties(BeetlProperties.newInstance());
return beetlConfiguration;
}
/**
* beetl的视图解析器
*/
@Bean
public BeetlSpringViewResolver beetlViewResolver() {
BeetlSpringViewResolver beetlSpringViewResolver = new BeetlSpringViewResolver();
beetlSpringViewResolver.setConfig(beetlConfiguration());
beetlSpringViewResolver.setContentType("text/html;charset=UTF-8");
beetlSpringViewResolver.setOrder(0);
return beetlSpringViewResolver;
}
/**
* druidServlet注册
*/
......@@ -86,8 +54,4 @@ public class WebConfig {
public ServletListenerRegistrationBean<ConfigListener> configListenerRegistration() {
return new ServletListenerRegistrationBean<>(new ConfigListener());
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
}
......@@ -2,11 +2,18 @@
guns:
kaptcha-open: false #是否开启登录时验证码 (true/false)
################### 项目启动端口 ###################
server:
port: 80
################### beetl配置 ###################
beetl:
delimiter-statement-start: \@ #开始结束标签(yaml不允许@开头)
delimiter-statement-end: null
resource-tagroot: common/tags #自定义标签文件Root目录和后缀
resource-tagsuffix: tag
################### spring配置 ###################
spring:
profiles:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment