freemark 全局变量 定义 不生效


方法-:

<bean id="freemarkerConfiguration"
      class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="location" value="classpath:advtopic.properties" />
bean>

<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">10prop>
            <prop key="locale">zh_CNprop>
            <prop key="datetime_format">yyyy-MM-ddprop>
            <prop key="date_format">yyyy-MM-ddprop>
            <prop key="number_format">#.##prop>
            <prop key="classic_compatible">trueprop>
        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.pluginsgroupId>
            <artifactId>maven-war-pluginartifactId>
            <version>2.6version>
            <configuration>
                <webResources>
                    <resource>
                        <directory>src/main/webapp/directory>
                        <includes>
                            <include>*.*include>
                            <include>**/*.*include>
                        includes>
                        <filtering>truefiltering>
                    resource>
                webResources>
            configuration>
        plugin>
    plugins>

    <resources>
        <resource>
            <directory>src/main/resourcesdirectory>
            <filtering>truefiltering>
        resource>
        <resource>
            <directory>src/main/resources/${run.environment}directory>
            <filtering>truefiltering>
        resource>
    resources>

build>


<xpurl>xpurl>


你可能感兴趣的:(java,web,开发)