spring中有关freeer的配置如下:<bean id="cmsListDirective" class="com.wki.web.directive.CmsListDirective"/>

<bean id="freeMarkerConfigurer" class="org.springframework.web.servlet.view.freeer.FreeMarkerConfigurer">
   <property name="freeerVariables">
   <map>
   <entry key="cms_list" value-ref="cmsListDirective"/>
   </map>
   </property>
   <property name="freeerSettings">
   <props>
   <prop key="locale">zh_CN</prop>
   <prop key="template_update_delay">0</prop>
<prop key="defaultEncoding">UTF-8</prop>
<prop key="url_escaping_charset">UTF-8</prop>
<prop key="boolean_format">true,false</prop>
<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
<prop key="date_format">yyyy-MM-dd</prop>
<prop key="time_format">HH:mm:ss</prop>
<prop key="number_format">0.######</prop>
<prop key="whitespace_stripping">true</prop>
   </props>
   </property>
</bean>

<bean id="viewResolver" class="org.springframework.web.servlet.view.freeer.FreeMarkerViewResolver">
   <property name="cache" value="true"/>
   <property name="prefix" value=""/>
   <property name="suffix" value=".ftl"/>
   <property name="exposeSpringMacroHelpers" value="true"/>
</bean>其中cmsListDirective 是自定义指令,问题在于该配置不起任何作用,在模版中调用<@cms_list></@cms_list>报未找到异常。我整个项目的环境是:urlrewrite + struts2 + mybatis + spring3.0 + freeer求各位指点迷津!

解决方案 »

  1.   

        <bean id="freeerViewResolver" class="org.springframework.web.servlet.view.freeer.FreeMarkerViewResolver">
          <property name="cache" value="false"/>
          <property name="prefix" value=""/>
          <property name="suffix" value=".html"/>
          <property name="exposeSpringMacroHelpers" value="true"/>
          <property name="exposeRequestAttributes" value="false"/>
          <property name="exposeSessionAttributes" value="false"/>
          <property name="contentType" value="text/html;charset=UTF-8"/>
          <property name="requestContextAttribute" value="rc"></property>
        </bean>
        
    <bean id="freeerConfig" class="org.springframework.web.servlet.view.freeer.FreeMarkerConfigurer">
    <property name="templateLoaderPath" value="/WEB-INF/template/front"/>
    <property name="freeerVariables">
    <map>
    <entry key="cms_channel" value-ref="channelDirective"/>
    <entry key="cms_channel_list" value-ref="channelListDirective"/>
    <entry key="cms_content_list" value-ref="contentListDirective"/>
    <entry key="cms_content" value-ref="contentContextlDirective"/>
    <entry key="cms_navigation" value-ref="navigationDirective"/>
    <entry key="cms_menu" value-ref="menuDirective"/>
    <entry key="cms_hotcontent_list" value-ref="hotContentListDirective"/>
    <entry key="cms_questionnaire_list" value-ref="questionnaireListDirective"/>
    <entry key="cms_hotquestionnaire_list" value-ref="hotQuestionnaireListDirective"/>
    <entry key="cms_relative_list" value-ref="relativeListDirective"/>
    <entry key="cms_enterprise_list" value-ref="enterpriseListDirective"/>
    <entry key="cms_region" value-ref="regionDirective"/>

    <entry key="shiro_authenticated" value-ref="authenticatedTag"/>
    <entry key="shiro_guest" value-ref="guestTag"/>
    <entry key="shiro_hasAnyRoles" value-ref="hasAnyRolesTag"/>
    <entry key="shiro_hasPermission" value-ref="hasPermissionTag"/>
                    <entry key="shiro_hasRole" value-ref="hasRoleTag"/>
                    <entry key="shiro_lacksPermission" value-ref="lacksPermissionTag"/>
                    <entry key="shiro_lacksRole" value-ref="lacksRoleTag"/>
                    <entry key="shiro_notAuthenticated" value-ref="notAuthenticatedTag"/>
                    <entry key="shiro_principal" value-ref="principalTag"/>
                    <entry key="shiro_user" value-ref="userTag"/>
    </map>
    </property>
    <property name="freeerSettings">
    <props>
    <prop key="tag_syntax">auto_detect</prop>
    <prop key="template_update_delay">5</prop>
    <prop key="defaultEncoding">UTF-8</prop>
    <prop key="url_escaping_charset">UTF-8</prop>
    <prop key="locale">zh_CN</prop>
    <prop key="boolean_format">true,false</prop>
    <prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
    <prop key="date_format">yyyy-MM-dd</prop>
    <prop key="time_format">HH:mm:ss</prop>
    <prop key="number_format">#</prop>
    <prop key="whitespace_stripping">true</prop>
    <!--空值处理<prop key="classic_compatible">true</prop>-->
    </props>
    </property>
    </bean>
    我们是这么配的,只不过我们的bean使用annotation注入的,前台ftl是这么写的[@cms_channel][/@cms_channel]
      

  2.   


    我的bean也是使用annotation注入的,现在按照你的配置还是不起作用。
    是不是struts2 的配置文件中还要加其他的内容?
      

  3.   

    我们没用struts,你可以看一下是不是被struts的拦截器拦截了
      

  4.   

    如果用annotation,注入的话只需要在com.wki.web.directive.CmsListDirective的类定义前面加上@Component就可以了,不用在xml里面配<bean id="cmsListDirective" class="com.wki.web.directive.CmsListDirective"/>这个了吧。
    我们freeer自定义标签是这样写的@Component
    public class ChannelListDirective implements TemplateDirectiveModel {
        // 栏目管理的业务类
        @Autowired
        private ChannelManager channelManager;    /**
         * execute 实现接口方法
         * 
         * @param Environment
         *            env 上下文环境
         * @param Map
         *            params 参数的map
         * @param TemplateModel
         *            loopVars 循环变量
         * @param TemplateDirectiveBody
         *            body
         * @return void
         * @throws 无
         * ==============================================
         * 2012-05-22 gooton-刘忠映 新增
         * ==============================================
         */
        public void execute(Environment env, Map params, TemplateModel[] loopVars,
                TemplateDirectiveBody body) throws TemplateException, IOException {
            // 父id
            String parentId = params.get("parentId") == null ? null : params.get(
                    "parentId").toString();
            // 站点ID
            String siteId = params.get("siteId") == null ? null : params.get(
                    "siteId").toString();
            // 是否有内容
            String hasContent = params.get("hasContent") == null ? null : params
                    .get("hasContent").toString();
            // 生成查询对象
            Search search = Search.build();
            // 父id存在
            if (!StringUtils.isBlank(parentId)) {
                search.addFilterEqual("parent.id", Long.parseLong(parentId));
            } else {
                search.addFilterEqual("level", "0");
            }        // 站点id存在
            if (!StringUtils.isBlank(siteId)) {
                search.addFilterEqual("site.id", Long.parseLong(siteId));
            }
            // 是否有内容
            if (!StringUtils.isBlank(hasContent)) {
                search.addFilterEqual("hasContent", "1".equals(hasContent) ? true
                        : false);
            }
            search.addFilterEqual("sysFlag", "1");
            // 按优先级排序
            search.addSortAsc("priority");
            List<Channel> channels = channelManager.findChannelList(search);
            env.setVariable(Constant.OUT_LIST, DEFAULT_WRAPPER.wrap(channels));
            body.render(env.getOut());
        }
    }
      

  5.   

    谢谢你的回复,问题我已经找到了。
    是struts2配置文件中还要加一段配置:<constant name="struts.freeer.manager.classname" value="com.wki.commons.freeer.FreeerManager"/>
    public class FreeerManager extends
    org.apache.struts2.views.freeer.FreeerManager { protected Configuration createConfiguration(ServletContext servletContext)
    throws TemplateException {
    FreeMarkerConfigurer configurer = (FreeMarkerConfigurer) BeanUtils
    .getContext(servletContext).getBean("freeMarkerConfigurer");
    return configurer.getConfiguration();
    }}这样就行了。