I'm trying to develop a simple REST WS that connects to an embedded Neo4J DB that runs locally on my machine. First I got a simple GET operation just returning a simple String when the Service was called and that works normally. Now I'm trying to get this to really do something so I've searched a couple of tutorials on how to integrate Spring with Neo4J. The truth is I've found this to be much more tricky than what I was expecting, mainly because there's a lot of tutorials and they all look different, so there's like 100 different ways to do it and I'm trying to adapt to my solution. I'm not sure on my Annotations and also on my XML configuration files. Any help is apreciatted. May the Force be with me. :)
UPDATE_1: this is myStore servlet now
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:mvc="http://www.springframework.org/schema/mvc" 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.0.xsd http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="com.ruitex23.myStore" />
<jpa:repositories base-package="com.ruitex23.myStore.repositories" />
<bean name="soapOperationRepository" class="com.ruitex23.myStore.services.SoapOperationService" />
<context:annotation-config />
</beans>
The Controller
package com.ruitex23.myStore.controllers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.ruitex23.myStore.domains.SoapOperation;
import com.ruitex23.myStore.services.SoapOperationService;
@RestController
public class SpringRestController {
@Autowired SoapOperationService operationService;
//the dummy method
@RequestMapping(value = "/hello/{name}", method = RequestMethod.GET)
public String hello(@PathVariable String name) {
String result = "Hallo " + name;
return result;
}
//the real method
@RequestMapping(value = "/soapOperation/{version}", method = RequestMethod.GET)
public SoapOperation getSoapOperationByVersion(@PathVariable("version") Integer version) {
return operationService.searchBySoapOperationVersion(String.valueOf(version));
}
}
The Repository
package com.ruitex23.myStore.repositories;
/**
*
*/
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.data.repository.query.Param;
import com.ruitex23.myStore.domains.SoapOperation;
/**
* @author ruitex23
*
*/
public interface SoapOperationRepository extends GraphRepository<SoapOperation> {
SoapOperation findBySoapOperationVersion(@Param("soapOperationVersion") String soapOperationVersion);
}
The Service
package com.ruitex23.myStore.services;
/**
*
*/
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruitex23.myStore.domains.SoapOperation;
import com.ruitex23.myStore.repositories.SoapOperationRepository;
/**
* @author ruitex23
*
*/
@Service
public class SoapOperationService {
@Autowired SoapOperationRepository soapOperationRepository;
public SoapOperation searchBySoapOperationVersion(String operationVersion) {
return soapOperationRepository.findBySoapOperationVersion(operationVersion);
}
}
MyStore Servlet
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" 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.0.xsd http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="com.ruitex23.myStore" />
//read somewhere that the interface should point to the impl
<bean name="soapOperationRepository" class="com.ruitex23.myStore.services.SoapOperationService" />
<context:annotation-config />
</beans>
web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>myStore</display-name>
<servlet>
<servlet-name>mystore</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mystore</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
And now the error related to the Autowired object.
12:05:58.649 [main] WARN o.s.w.c.s.XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springRestController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.ruitex23.myStore.services.SoapOperationService com.ruitex23.myStore.controllers.SpringRestController.operationService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'soapOperationService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.ruitex23.myStore.repositories.SoapOperationRepository ruitex23.myStore.services.SoapOperationService.soapOperationRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.ruitex23.myStore.repositories.SoapOperationRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
The error continues on and on, but I think this the important part. If u need to see anything else of the log error let me know.
Thank in advance