【问题标题】:Intergrating AEM/CQ5 and Spring Framework?集成 AEM/CQ5 和 Spring 框架?
【发布时间】:2016-06-17 07:02:40
【问题描述】:

我一直在尝试将 Spring 框架集成到 AEM6/CQ5 中。

我正在学习本教程。 LINK

按照教程,我已经安装了 NEBA 包。 所有 NEBA 包都在 OSGi 控制台中处于活动状态。

然后我创建了自己的Maven CQ5项目,添加了Neba注解和Spring的依赖。我的项目也成功部署在了CQ5(bundle is active)。

我尝试使用 NEBA 的 ResourceModel 注释。但是这个模型并没有出现在 NEBA 的模型注册表中。 我将 ResourceModel 映射到我创建的内容组件“linkComponent”。

当用户将其拖放到任何 parsys 上时,资源节点具有属性 linkNamelinkURL

我尝试在 JSP 中访问这些值,但失败了。

请看下面的代码: 包 com.zensar.neba;

import org.apache.sling.api.resource.Resource;

import io.neba.api.annotations.Path;
import io.neba.api.annotations.ResourceModel;

@ResourceModel(types = "zensar-neba/components/content/linkComponent")
public class LinkComponent {

    private String linkName;
    private String linkURL;

    public String getLinkName() {
        return linkName;
    }
    public void setLinkName(String linkName) {
        this.linkName = linkName;
    }
    public String getLinkURL() {
        return linkURL;
    }
    public void setLinkURL(String linkURL) {
        this.linkURL = linkURL;
    }


}

请看下面linkComponent的JSP代码:

<%@include file="/libs/foundation/global.jsp"%>
<%@taglib prefix="neba" uri="http://neba.io/1.0"%>
<neba:defineObjects />
Link Component
<a href="${m.linkURL}"> Click Here ${m.linkName}</a>

然后我尝试使用 Spring 注释 创建一个 Controller,但我得到了 "Path not found" 我错过了什么。

请看下面的代码:

package com.zensar.neba;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class DemoController {
    @RequestMapping("/echo/{param}")
    @ResponseBody
    public String echo(@PathVariable("param") String paramToEcho) {
       return "Hello "+ paramToEcho;
    }
}

我将控制器链接称为:http://localhost:4502/bin/mvc.do/echo/Oliver

重要提示: 我所有的捆绑包都处于活动状态

【问题讨论】:

    标签: spring spring-mvc aem aem-6


    【解决方案1】:

    如果所有捆绑包都已启动并运行,并且您看到模型注册表,则表示一切运行顺利。但是:你的模型没有出现,这意味着你的包的应用程序上下文没有运行。 NEBA 使用gemini-blueprint,它是OSGi 蓝图规范的参考实现。

    您是否有 xml 文件,例如blueprint.xml,在捆绑包的 OSGI-INF/blueprint 文件夹中?它应该是这样的:

    <?xml version="1.0" encoding="UTF-8"?>
    <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"
           xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
       http://www.osgi.org/xmlns/blueprint/v1.0.0
       http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.2.xsd">
    
        <context:component-scan base-package="com.zensar.neba" />
    </beans>
    

    如果你这样做了,当你的包启动时你的 error.log 会说什么? 作为参考,这里是一个使用 NEBA 的示例 webapp:https://github.com/unic/publication-neba-adaptto-2015

    还有一点:NEBA 使用私有字段注入,因此您的 bean 上不需要任何设置器。

    【讨论】:

    • 嗨@Olaf我没有这个xml文件。你能告诉我把这个文件放在我的 CQ5 Maven 项目的什么地方吗?
    • 如果我有一亿美元,我会把它们给你。我添加了 context.xml,一切正常,谢谢
    【解决方案2】:

    很高兴能帮上忙!只是为了回答您的最后一个问题:在 maven 项目中,蓝图 XML 文件的正确位置应位于包含您的模型/控制器的 maven 模块的 src/main/resources/OSGI-INF/blueprint 文件夹中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-31
      • 1970-01-01
      • 2018-04-03
      • 1970-01-01
      • 1970-01-01
      • 2013-03-19
      • 1970-01-01
      • 2016-10-26
      相关资源
      最近更新 更多