方法-: <!--freemarker 注入全局变量-->
< bean id ="freemarkerConfiguration"
class ="org.springframework.beans.factory.config.PropertiesFactoryBean" >
< property name ="location" value ="classpath:advtopic.properties" />
</ bean >
<!-- freemarker 相关 -->
< bean id ="freemarkerConfig" class ="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer" >
< property name ="templateLoaderPath" value ="/WEB-INF/view/" />
< property name ="defaultEncoding" value ="utf-8" />
< property name ="freemarkerSettings" >
< props >
< prop key ="template_update_delay" > 10</ prop >
< prop key ="locale" > zh_CN</ prop >
< prop key ="datetime_format" > yyyy-MM-dd</ prop >
< prop key ="date_format" > yyyy-MM-dd</ prop >
< prop key ="number_format" > #.##</ prop >
< prop key ="classic_compatible" > true</ prop >
</ props >
</ property >
< property name ="freemarkerVariables" >
< map >
< entry key ="xpurl" value ="${ xpurl}" ></ entry >
</ map >
</ property >
</ bean >
这样是不生效的。要更改java代码
添加如下代码
@Configuration
@PropertySource ("classpath:xxx.properties" )
public class ApiConfig {
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
方法二
< build >
< plugins >
< plugin >
< groupId > org.apache.maven.plugins</ groupId >
< artifactId > maven-war-plugin</ artifactId >
< version > 2.6</ version >
< configuration >
< webResources >
< resource >
< directory > src/main/webapp/</ directory >
< includes >
< include > *.*</ include >
< include > **/*.*</ include >
</ includes >
< filtering > true</ filtering >
</ resource >
</ webResources >
</ configuration >
</ plugin >
</ plugins >
< resources >
< resource >
< directory > src/main/resources</ directory >
< filtering > true</ filtering >
</ resource >
< resource >
< directory > src/main/resources/${run.environment}</ directory >
< filtering > true</ filtering >
</ resource >
</ resources >
</ build >
< xpurl></ xpurl>