I am getting a little bit lost in trying to integrate spring and jersey in my spring-data-neo4j unmanaged server plugin. I have created POJO models with neo4j annotations for persisting in the store. On top of that I have created spring-data-neo4j repositories for operations over the data. I created a springContext.xml file and placed it under the resources folder.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
xmlns:neo4j="http://www.springframework.org/schema/data/neo4j" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd">
<context:annotation-config />
<context:spring-configured />
<neo4j:repositories base-package="com.mycompany.poc.graph.repositories" />
<context:component-scan base-package="com.mycompany.poc.rest" />
</beans>
Further, i have setup SpringPluginInitializer and initialized the springContext.xml.
import com.mycompany.poc.graph.repositories.NodeObjectGraphRepository;
public class SpringExtensionInitializer extends SpringPluginInitializer {
@SuppressWarnings("unchecked")
public SpringExtensionInitializer() {
super(new String[] {
"META-INF/spring/springContext.xml"
}, expose("template", Neo4jTemplate.class),
expose("nodeObjectGraphRepository", NodeObjectGraphRepository.class),
expose("pathController", PathController.class));
}
}
I have exposed business services through PathController a Jersey Rest end point.
package com.mycompany.poc.rest;
import com.mycompany.poc.graph.repositories.NodeObjectGraphRepository;
@Path("/path")
@Component
public class PathController {
@Autowired NodeObjectGraphRepository nodeObjectGraphRepository;
@GET
@Path("/paths")
@Produces(MediaType.APPLICATION_JSON)
public Response paths(@QueryParam("startNode") Long startNodeId, @QueryParam("endNode") Long endNodeId) {
Response response = null;
if( startNodeId != null && endNodeId != null){
try{
EndResult endResult = nodeObjectGraphRepository.getPathsBetweenNodes(startNodeId, endNodeId);
response = Response.ok().entity(endResult).build();
}catch(Exception e){
response = Response.serverError().entity(ExceptionUtils.getFullStackTrace(e)).build();
}
}else{
response = Response.serverError().entity("Invalid Inputs").build();
}
return response;
}
}
I have annotated PathController class with Spring stereotypes "Component" and also injected "NodeObjectGraphRepository" object through Spring Autowiring. However, i get a null nodeObjectGraphRepository object and hence not able to use the repositories. In the springContext.xml, I have setup scan for spring data neo4j repositories and Jersey controller annotated with Spring stereotype "Component". I am not able to figure how to inject spring dependencies. Any help is very much appreciated.