1

我正在使用Neo4j嵌入式模式spring 数据aspectj映射。

相关POM切片:

  <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j</artifactId>
        <version>2.2.0.RELEASE</version>
    </dependency>
  <dependency>
        <groupId>org.neo4j.app</groupId>
        <artifactId>neo4j-server</artifactId>
        <version>1.8</version>
    </dependency>
    <dependency>
        <groupId>org.neo4j.app</groupId>
        <artifactId>neo4j-server</artifactId>
        <version>1.8</version>
        <classifier>static-web</classifier>
    </dependency>  
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j-aspects</artifactId>
        <version>2.2.0.RELEASE</version>
    </dependency> 

context.xml 内容:

<util:properties id="props" location="classpath:app.properties" />
<context:spring-configured />

<context:component-scan base-package="com.writelife.server.services" />
<tx:annotation-driven />

<!--<import resource="mongo-config.xml" /> -->
<import resource="neo4j-config.xml" />

Neo4j-config.xml 内容:

<context:annotation-config />
<context:spring-configured />

<bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase">
    <constructor-arg value="c:/neo4j-community-1.8-writelife/data/graph.db" />
    <constructor-arg>
        <map>
            <entry key="enable_remote_shell" value="true" />
        </map>
    </constructor-arg>
</bean>

<neo4j:config graphDatabaseService="graphDatabaseService" />
<bean id="serverWrapper" class="org.neo4j.server.WrappingNeoServerBootstrapper"
    init-method="start" destroy-method="stop">
    <constructor-arg ref="graphDatabaseService" />
</bean>

<bean id="neo4jTransactionManager"
    class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="transactionManager">
        <bean class="org.neo4j.kernel.impl.transaction.SpringTransactionManager">
            <constructor-arg ref="graphDatabaseService" />
        </bean>
    </property>
    <property name="userTransaction">
        <bean class="org.neo4j.kernel.impl.transaction.UserTransactionImpl">
            <constructor-arg ref="graphDatabaseService" />
        </bean>
    </property>
</bean>

<tx:annotation-driven mode="aspectj"
    transaction-manager="neo4jTransactionManager" />

<neo4j:repositories base-package="com.writelife.server.graph.repository"
    repository-impl-postfix="CustomImpl" />

我正在通过扩展 GrapRepository 的存储库和通过 aspectj 支持的节点/关系(域驱动开发)与 Neo4j 进行交互....

当我尝试使用 @Transactional("transactionManager") 或 @Transactional("neo4jTransactionManager") 注释我的服务时,我希望事务从服务级别开始

例如:

 @Service
 @Transactional("transactionManager")
 public class StoryService extends AbstarctCrudService<Story>

我在与自动接线相关的弹簧上下文加载中遇到异常...

   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 

任何人都可以帮助我做错了什么?如何在不损坏自动接线的情况下设置事务?

谢谢

4

0 回答 0