Commit ab03d056 by fsn

重新整理beetl配置

parent 6e647ca5
package com.stylefeng.guns.config.properties; 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; import java.util.Properties;
/** /**
* beetl配置 * beetl配置(如果需要配置别的配置可参照这个形式自己添加)
* *
* @author fengshuonan * @author fengshuonan
* @date 2017-05-22 18:45 * @date 2017-05-24 20:37
*/ */
@Configuration
@ConfigurationProperties(prefix = BeetlProperties.BEETLCONF_PREFIX)
public class BeetlProperties { 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(){ public String getDelimiterStatementStart() {
init(); return delimiterStatementStart;
} }
public void init() { public void setDelimiterStatementStart(String delimiterStatementStart) {
//开始结束占位符 this.delimiterStatementStart = delimiterStatementStart;
this.properties.setProperty("DELIMITER_PLACEHOLDER_START", "${"); }
this.properties.setProperty("DELIMITER_PLACEHOLDER_END", "}");
//开始结束标签 public String getDelimiterStatementEnd() {
this.properties.setProperty("DELIMITER_STATEMENT_START", "@"); return delimiterStatementEnd;
this.properties.setProperty("DELIMITER_STATEMENT_END", "null"); }
//classpath 根路径 public void setDelimiterStatementEnd(String delimiterStatementEnd) {
this.properties.setProperty("RESOURCE.root", "/"); this.delimiterStatementEnd = delimiterStatementEnd;
}
//是否检测文件变化 public String getResourceTagroot() {
this.properties.setProperty("RESOURCE.autoCheck", "true"); return resourceTagroot;
}
//beetl HTMl标签 public void setResourceTagroot(String resourceTagroot) {
this.properties.setProperty("HTML_TAG_FLAG", "#"); this.resourceTagroot = resourceTagroot;
}
//自定义标签文件Root目录和后缀 public String getResourceTagsuffix() {
this.properties.setProperty("RESOURCE.tagRoot", "common/tags"); return resourceTagsuffix;
this.properties.setProperty("RESOURCE.tagSuffix", "tag");
} }
public static Properties newInstance(){ public void setResourceTagsuffix(String resourceTagsuffix) {
return beetlProperties.properties; 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; package com.stylefeng.guns.config.web;
import com.alibaba.druid.support.http.StatViewServlet; 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.listener.ConfigListener;
import com.stylefeng.guns.core.util.xss.XssFilter; 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.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean; import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean;
...@@ -22,35 +17,8 @@ import org.springframework.web.context.request.RequestContextListener; ...@@ -22,35 +17,8 @@ import org.springframework.web.context.request.RequestContextListener;
* @date 2016年11月12日 下午5:03:32 * @date 2016年11月12日 下午5:03:32
*/ */
@Configuration @Configuration
@ConfigurationProperties(prefix = "spring.mvc.view")
public class WebConfig { 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注册 * druidServlet注册
*/ */
...@@ -86,8 +54,4 @@ public class WebConfig { ...@@ -86,8 +54,4 @@ public class WebConfig {
public ServletListenerRegistrationBean<ConfigListener> configListenerRegistration() { public ServletListenerRegistrationBean<ConfigListener> configListenerRegistration() {
return new ServletListenerRegistrationBean<>(new ConfigListener()); return new ServletListenerRegistrationBean<>(new ConfigListener());
} }
public void setPrefix(String prefix) {
this.prefix = prefix;
}
} }
...@@ -2,11 +2,18 @@ ...@@ -2,11 +2,18 @@
guns: guns:
kaptcha-open: false #是否开启登录时验证码 (true/false) kaptcha-open: false #是否开启登录时验证码 (true/false)
################### 项目启动端口 ################### ################### 项目启动端口 ###################
server: server:
port: 80 port: 80
################### beetl配置 ###################
beetl:
delimiter-statement-start: \@ #开始结束标签(yaml不允许@开头)
delimiter-statement-end: null
resource-tagroot: common/tags #自定义标签文件Root目录和后缀
resource-tagsuffix: tag
################### spring配置 ################### ################### spring配置 ###################
spring: spring:
profiles: 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