11-27-2019 02:45 AM
hello.
I try to create additional module for Alfresco.
I created project All-in-One by instruction https://github.com/Alfresco/alfresco-sdk/blob/master/docs/getting-started.md
SDK 4.0, Alfresco 6.1
in class DemoComponent
import org.alfresco.repo.nodelocator.NodeLocatorService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
private NodeService nodeService;
private NodeLocatorService nodeLocatorService;
public NodeRef getCompanyHome(){
return nodeLocatorService.getNode("companyhome", null, null);
}
<bean id="testpackage.DemoComponent" class="testpackage.platformsample.DemoComponent" parent="module.baseComponent" >
<property name="moduleId" value="testartifact-platform" /> <!-- See module.properties -->
<property name="name" value="DemoComponent" />
<property name="description" value="A demonstration component" />
<property name="sinceVersion" value="2.0" />
<property name="appliesFromVersion" value="2.0" /> <!-- 1.0 would not work here when using SNAPSHOT version in project -->
<property name="nodeService" ref="nodeService" />
<property name="nodeLocatorService" ref="nodeLocatorService" />
</bean>
I run project (./run.sh build_start), but line getCompanyHome() take me error
java.lang.NullPointerException
at testpackage.platformsample.DemoComponent.getCompanyHome(DemoComponent.java:93)
at testpackage.platformsample.DemoComponent.executeInternal(DemoComponent.java:61)
at testpackage.platformsample.HelloWorldWebScript.executeImpl(HelloWorldWebScript.java:129)
at testpackage.platformsample.HelloWorldWebScriptControllerTest.testController(HelloWorldWebScriptControllerTest.java:47)
How can I get nodeService, nodeLocatorService?
Maybe anybody link me to example project, please.
I would be very grateful for the information. Thanks to all.
Tetyana
11-27-2019 05:53 AM
Do you have a setter service for NodeService and NodeServiceLocator beans in your Java class?
11-27-2019 10:26 AM
only this
in DemoComponent:
public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;
}
public void setNodeLocatorService(NodeLocatorService nodeLocatorService) {
this.nodeLocatorService = nodeLocatorService;
}
11-27-2019 02:33 PM
Remember to write the setter method
public void setNodeService(NodeService nodeService) { this.nodeService = nodeService; }
... for each Spring injected field.
If the method is missing you will get null exception!
11-27-2019 02:51 PM
Ok I saw now that methods are there.
Maybe the problem is the property injection on xml.
The correct way is
<property name="nodeService" ref="NodeService" />
Note the initial uppercase on ref attribute.
11-28-2019 02:44 AM
it`s not solution
11-29-2019 03:00 PM
Is it possible for you to share the project you have created using SDK4.x? You can zip it and attach here.
12-02-2019 05:01 AM
12-04-2019 02:11 PM
Check the response here: https://hub.alfresco.com/t5/alfresco-content-services-forum/re-how-get-nodeservice-in-project-all-in...
12-02-2019 05:04 AM
Explore our Alfresco products with the links below. Use labels to filter content by product module.