title: Spring Neo4j with aspectj, transactions configuration
body: <p>I am working with <strong>Neo4j</strong> in <strong>embedded</strong> mode, <strong>spring data</strong> and <strong>aspectj</strong> mapping.</p>
  
  <p><em><strong>Relevant POM slices:</em></strong></p>
  
  <pre><code>  &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
          &lt;artifactId&gt;spring-data-neo4j&lt;/artifactId&gt;
          &lt;version&gt;2.2.0.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
    &lt;dependency&gt;
          &lt;groupId&gt;org.neo4j.app&lt;/groupId&gt;
          &lt;artifactId&gt;neo4j-server&lt;/artifactId&gt;
          &lt;version&gt;1.8&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.neo4j.app&lt;/groupId&gt;
          &lt;artifactId&gt;neo4j-server&lt;/artifactId&gt;
          &lt;version&gt;1.8&lt;/version&gt;
          &lt;classifier&gt;static-web&lt;/classifier&gt;
      &lt;/dependency&gt;  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
          &lt;artifactId&gt;spring-data-neo4j-aspects&lt;/artifactId&gt;
          &lt;version&gt;2.2.0.RELEASE&lt;/version&gt;
      &lt;/dependency&gt; 
  </code></pre>
  
  <p><em><strong>context.xml content:</em></strong>  </p>
  
  <pre><code>&lt;util:properties id="props" location="classpath:app.properties" /&gt;
  &lt;context:spring-configured /&gt;
  
  &lt;context:component-scan base-package="com.writelife.server.services" /&gt;
  &lt;tx:annotation-driven /&gt;
  
  &lt;!--&lt;import resource="mongo-config.xml" /&gt; --&gt;
  &lt;import resource="neo4j-config.xml" /&gt;
  </code></pre>
  
  <p><em><strong>Neo4j-config.xml content:</em></strong></p>
  
  <pre><code>&lt;context:annotation-config /&gt;
  &lt;context:spring-configured /&gt;
  
  &lt;bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase"&gt;
      &lt;constructor-arg value="c:/neo4j-community-1.8-writelife/data/graph.db" /&gt;
      &lt;constructor-arg&gt;
          &lt;map&gt;
              &lt;entry key="enable_remote_shell" value="true" /&gt;
          &lt;/map&gt;
      &lt;/constructor-arg&gt;
  &lt;/bean&gt;
  
  &lt;neo4j:config graphDatabaseService="graphDatabaseService" /&gt;
  &lt;bean id="serverWrapper" class="org.neo4j.server.WrappingNeoServerBootstrapper"
      init-method="start" destroy-method="stop"&gt;
      &lt;constructor-arg ref="graphDatabaseService" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="neo4jTransactionManager"
      class="org.springframework.transaction.jta.JtaTransactionManager"&gt;
      &lt;property name="transactionManager"&gt;
          &lt;bean class="org.neo4j.kernel.impl.transaction.SpringTransactionManager"&gt;
              &lt;constructor-arg ref="graphDatabaseService" /&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
      &lt;property name="userTransaction"&gt;
          &lt;bean class="org.neo4j.kernel.impl.transaction.UserTransactionImpl"&gt;
              &lt;constructor-arg ref="graphDatabaseService" /&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;tx:annotation-driven mode="aspectj"
      transaction-manager="neo4jTransactionManager" /&gt;
  
  &lt;neo4j:repositories base-package="com.writelife.server.graph.repository"
      repository-impl-postfix="CustomImpl" /&gt;
  </code></pre>
  
  <p>I am interacting with Neo4j via Repositories which extends GrapRepository and via aspectj backed nodes/relationships (Domain Driven Development)....</p>
  
  <p>I want transactions will start from the <strong>Services</strong> level, when I am trying to annotate my services with @Transactional("transactionManager") or @Transactional("neo4jTransactionManager") </p>
  
  <p>For example:</p>
  
  <pre><code> @Service
   @Transactional("transactionManager")
   public class StoryService extends AbstarctCrudService&lt;Story&gt;
  </code></pre>
  
  <p>I am getting exceptions in spring context loading related to auto-wiring...</p>
  
  <pre><code>   org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'utilsService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.writelife.server.services.StoryService com.writelife.server.services.UtilsService.storyService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.writelife.server.services.StoryService] 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:287) ~[spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106) ~[spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) ~[spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) ~[spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) ~[spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) ~[spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) ~[spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607) ~[spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:925) ~[spring-context-3.1.4.RELEASE.jar:3.1.4.RELEASE]
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:472) ~[spring-context-3.1.4.RELEASE.jar:3.1.4.RELEASE]
  at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:388) ~[spring-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
  at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:293) ~[spring-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
  at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) [spring-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
  at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791) [catalina.jar:7.0.33]
  at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285) [catalina.jar:7.0.33]
  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:7.0.33]
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) [catalina.jar:7.0.33]
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) [catalina.jar:7.0.33]
  at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) [na:1.7.0_02]
  at java.util.concurrent.FutureTask.run(Unknown Source) [na:1.7.0_02]
  at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.7.0_02]
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.7.0_02]
  at java.lang.Thread.run(Unknown Source) [na:1.7.0_02]
      Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.writelife.server.services.StoryService com.writelife.server.services.UtilsService.storyService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.writelife.server.services.StoryService] 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$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:513) ~[spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
  at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:92) ~[spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284) ~[spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
  ... 23 common frames omitted
    Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.writelife.server.services.StoryService] 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.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:947) ~[spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:816) ~[spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:730) ~[spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:485) ~[spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
  ... 25 common frames omitted 
  </code></pre>
  
  <p>Any one can help what am I doing wrong ? how to set the transactions without damaging the auto-wiring?</p>
  
  <p>Thanks</p>