Spring Data Rest与Spring Data Neo4J不兼容?

时间:2015-07-25 17:51:22

标签: spring neo4j spring-data spring-data-neo4j spring-data-rest

我试图将Spring Data Rest合并到使用Spring Data Neo4J的应用程序中。当我将Spring Data Rest包含到我的应用程序中时,我在启动时遇到以下异常:

    18:41:10.632 [main] INFO  o.h.tool.hbm2ddl.SchemaUpdate - HHH000232: Schema update complete
    18:41:11.280 [main] WARN  o.e.j.u.component.AbstractLifeCycle - FAILED org.springframework.boot.context.embedded.jetty.ServletContextInitializerConfiguration$Initializer@2521bcf2: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter': Injection of autowired dependencies failed; nested exception is ...

    // very long stack trace here

    Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.neo4j.support.Neo4jTemplate]: Circular reference involving containing bean 'myApplication' - consider declaring the factory method as static for independence from its containing instance. Factory method 'neo4jTemplate' threw exception; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'neo4jMappingContext': Requested bean is currently in creation: Is there an unresolvable circular reference?
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        ... 277 common frames omitted
    Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'neo4jMappingContext': Requested bean is currently in creation: Is there an unresolvable circular reference?
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.beforeSingletonCreation(DefaultSingletonBeanRegistry.java:347) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:285) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at io.travelnet.TravelNetApplication$$EnhancerBySpringCGLIB$$6dfc1a9a.mappingInfrastructure(<generated>) ~[spring-core-4.1.6.RELEASE.jar:na]
        at org.springframework.data.neo4j.config.Neo4jConfiguration.neo4jTemplate(Neo4jConfiguration.java:136) ~[spring-data-neo4j-3.3.1.RELEASE.jar:na]
        at io.travelnet.TravelNetApplication$$EnhancerBySpringCGLIB$$6dfc1a9a.CGLIB$neo4jTemplate$83(<generated>) ~[spring-core-4.1.6.RELEASE.jar:na]
        at io.travelnet.TravelNetApplication$$EnhancerBySpringCGLIB$$6dfc1a9a$$FastClassBySpringCGLIB$$484acc9c.invoke(<generated>) ~[spring-core-4.1.6.RELEASE.jar:na]
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at io.travelnet.TravelNetApplication$$EnhancerBySpringCGLIB$$6dfc1a9a.neo4jTemplate(<generated>) ~[spring-core-4.1.6.RELEASE.jar:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_71]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_71]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_71]
        at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_71]
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        ... 278 common frames omitted

这是我的依赖列表:

dependencies {
    compile("org.springframework.boot:spring-boot-starter-batch")
    compile("org.springframework.cloud:spring-cloud-starter-aws")
    compile("org.springframework.cloud:spring-cloud-aws-autoconfigure")
    compile("commons-io:commons-io:2.4")

    compile("org.springframework.boot:spring-boot-starter-data-rest")
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.data:spring-data-neo4j:3.3.1.RELEASE")
    compile("org.springframework.data:spring-data-commons:1.10.1.RELEASE")
    compile("com.graphaware.neo4j:timetree:2.1.7.28.20")
    compile("com.graphaware.neo4j:common:2.1.7.28")
    compile("org.codehaus.jackson:jackson-mapper-asl:1.9.13")

    // these are needed to provide Neo4J web admin interface
    compile("org.neo4j.app:neo4j-server:2.1.8")
    compile("org.neo4j.app:neo4j-server:2.1.8:static-web")
    runtime("com.sun.jersey:jersey-server:1.17.1")
    runtime("com.sun.jersey:jersey-servlet:1.17.1")

    compile("org.codehaus.groovy:groovy")
    runtime("org.postgresql:postgresql:9.4-1201-jdbc41")
    //providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")

    testCompile("org.springframework.boot:spring-boot-starter-test")
    testCompile "org.spockframework:spock-core:0.7-groovy-2.0"
}

如果我发表评论compile("org.springframework.boot:spring-boot-starter-data-rest"),应用程序会按预期运行。

是否存在版本不匹配?

按照Michael的要求编辑添加主类的配置:

@Configuration
@EnableAutoConfiguration
@EnableAsync
@EnableScheduling
@SpringBootApplication
@EnableNeo4jRepositories(basePackages = "com.me.graph")
@EnableJpaRepositories(basePackages = "com.me.model")
@EnableTransactionManagement
class MyApplication extends Neo4jConfiguration implements CommandLineRunner {

    MyApplication() {
        setBasePackage("com.me.graph.domain");
    }

    @Bean(destroyMethod = "shutdown")
    public GraphDatabaseService graphDatabaseService() {
        return new GraphDatabaseFactory().newEmbeddedDatabase("graph/neo4j.db");
    }

    @Autowired
    GraphDatabaseService db;

    @Bean
    public SingleTimeTree timeTree() {
        return new SingleTimeTree(db)
    }

    @Autowired
    LocalContainerEntityManagerFactoryBean entityManagerFactory;

    @Override
    @Bean(name = "transactionManager")
    public PlatformTransactionManager neo4jTransactionManager(GraphDatabaseService db) throws Exception {
        return new ChainedTransactionManager(new JpaTransactionManager(entityManagerFactory.getObject()),
                new JtaTransactionManagerFactoryBean(graphDatabaseService()).getObject());
    }

    @Override
    public void run(String... strings) throws Exception {
        startNeo4jServer()
    }

    private static final Logger log = LoggerFactory.getLogger(MyApplication.class);


    public void startNeo4jServer() {

        // used for Neo4j browser
        try {
            WrappingNeoServerBootstrapper neoServerBootstrapper;
            GraphDatabaseAPI api = (GraphDatabaseAPI) db;

            ServerConfigurator config = new ServerConfigurator(api);
            config.configuration()
                    .addProperty(Configurator.WEBSERVER_ADDRESS_PROPERTY_KEY, "127.0.0.1");
            config.configuration()
                    .addProperty(Configurator.WEBSERVER_PORT_PROPERTY_KEY, "7474");

            neoServerBootstrapper = new WrappingNeoServerBootstrapper(api, config);
            neoServerBootstrapper.start();
        } catch(Exception e) {
            //handle appropriately
            log.error("Exception when starting N4J")

        }
        // end of Neo4j browser config

    }

    static void main(String[] args) {

        ApplicationContext ctx = SpringApplication.run(MyApplication.class, args);

        log.info("MyApplication started.");

    }

}

0 个答案:

没有答案