0

我在 Hippo CMS 中结合目录设置 Spring 时遇到问题。

我有一个配置了componentclassname:ServiceLinkListComponent的目录,因此我可以将组件拖放到频道管理器页面上的占位符中。

在遵循http://svn.onehippo.org/repos/hippo/hippo-cms7/testsuite/trunk/的示例之后,我添加了 Spring 支持,因此我必须将 componentclassname 更改为componentclassname:SpringBridgeHstComponent

不幸的是,我无法再将任何文档与组件链接,因为无法识别@ParametersInfo,因为它位于 SpringBridgeHstComponent 的 bean 中。

如何使用 spring 管理的目录组件?

组件类

@ParametersInfo(type = ServiceLinkListComponentInfo.class)
@Component
@Scope(value = "prototype")
public class ServiceLinkListComponent extends CommonComponent {

    private static Logger log = LoggerFactory.getLogger(ServiceLinkListComponent.class);

    @Autowired
    public TestService testService;

    @Override
    public void doBeforeRender(final HstRequest request, final HstResponse response) {
        super.doBeforeRender(request, response);
        final ServiceLinkListComponentInfo paramInfo = getComponentParametersInfo(request);
        final String documentPath = paramInfo.getDocument();
        log.debug("Calling EssentialsDocumentComponent for document path:  [{}]", documentPath);

        //String test = testService.test();

        setContentBeanForPath(documentPath, request, response);
        request.setAttribute(REQUEST_ATTR_PARAM_INFO, paramInfo);
    }
}

服务等级

@Component("testService")
public class TestService {

    public String test(){
        return "hello";
    }
}

applicationContext.xml(在资源/META-INF.hst-assembly.overrides 中)

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="com.xxx.yyy" />
</beans>

回购 在此处输入图像描述

4

2 回答 2

0

我找到了一种方法来做我想做的事,但我认为这是一个肮脏的解决方法。也许来自 HippoCMS 的一些人可以在这里提供帮助。

我创建了另一个类:

@ParametersInfo(type = ServiceLinkListComponentInfo.class)
public class ServiceLinkListSpringHstComponent extends SpringBridgeHstComponent {}

此类需要在目录中设置(而不是 SpringBridgeHstComponent)。我还尝试了一个嵌套类来摆脱第二个文件,但河马没有找到它。

于 2015-07-09T21:20:25.857 回答
0

我是桥牌课的原作者。我认为您已经找到了当前的限制和合理的解决方法。:-)

我同意解决方法不是很理想,因为您需要添加与组件​​配置一样多的 SpringBridgeHstComponent 子类。

你能在这里提交一张 JIRA 票来改进这个吗?- https://issues.onehippo.com/projects/HSTTWO

顺便说一句,我原本认为这只能在桥接类级别进行改进,但似乎需要在容器级别进行改进(尤其是相关模块(用于定位))。因此,需要对该模块进行更多调查。

于 2015-07-10T15:34:10.523 回答