Reputation: 6250
I have been trying to integrate Spring framework within AEM6/CQ5.
I am following this tutorial. LINK
As per the tutorial I have installed the NEBA package. All NEBA bundles are active in OSGi console.
Then I created my own Maven CQ5 project, I added the dependencies of Neba annotations and Spring. My project was also successfully deployed in CQ5(bundle is active).
I tried to use a ResourceModel annotation of NEBA. But this model does not appear in the model registry of NEBA. I mapped the ResourceModel to a content component that i created "linkComponent".
When the user drags and drops this on any parsys the resource node has the properties linkName and linkURL.
I tried accessing these values in JSP but I failed.
Please See code below : package 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;
}
}
Please See JSP Code of linkComponent below:
<%@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>
Then I tried creating an Controller using Spring annotation but I got "Path not found" what am I missing.
Please see code below:
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;
}
}
I called the controller link this : http://localhost:4502/bin/mvc.do/echo/Oliver
IMPORTANT NOTE: All my bundles are active
Upvotes: 2
Views: 2452
Reputation: 11
I'm glad to have helped! Just to answer your last question: In a maven project, the right location for the blueprint XML file would be in the src/main/resources/OSGI-INF/blueprint folder of the maven module containing your models / controllers.
Upvotes: 1
Reputation: 26
If all bundles are up and running and you are seeing the model registry, it means everything is running smoothly. But: your model doesn't show up, this means that the application context of your bundle isn't running. NEBA uses gemini-blueprint, the reference implementation of the OSGi blueprint specification.
Do you have an xml file, e.g. blueprint.xml, in the OSGI-INF/blueprint folder of your bundle? It should look like this:
<?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>
If you do, what does your error.log say when your bundle is starting? For reference, here is a sample webapp using NEBA: https://github.com/unic/publication-neba-adaptto-2015
One more thing: NEBA uses private field injection, so you don't need to have any setters on your bean.
Upvotes: 1