Springboot环境中为Freemarker配置全局共享的常量
新建一个配置类:
@Configuration
public class FreemarkerConfig
{
@Autowired
freemarker.template.Configuration configuration;
@Autowired
Environment env;
@PostConstruct
public void setConfigure() throws TemplateModelException
{
String url = env.getProperty("api.gateway.url", "/");
configuration.setSharedVariable("API_PATH", url);
}
}