2013-05-14 33 views
1

与此战斗了一段时间,无论使用哪种弹簧/新版本的组合,都无法超越此异常。Neo4jConfig,找不到默认的构造函数。 Spring REST Hateoas问题

任何帮助将不胜感激。

完整堆栈跟踪:http://pastebin.com/SDM7fsBA

org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'organizationRepository': 
Cannot resolve reference to bean 'neo4jTemplate' while setting bean property 'neo4jTemplate'; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'io.trips.rest.WebAppInitializer$Neo4jConfig': 
Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: 
Could not instantiate bean class [io.trips.rest.WebAppInitializer$Neo4jConfig$$EnhancerByCGLIB$$d147012]: 
No default constructor found; nested exception is java.lang.NoSuchMethodException: io.trips.rest.WebAppInitializer$Neo4jConfig$$EnhancerByCGLIB$$d147012.<init>() 

WebAppInitializer.java:

//@Import({JpaConfig.class, MongoConfig.class}) 
//@ImportResource("classpath:META-INF/spring/security-config.xml") 
@Configuration 
@Import({Neo4jConfig.class}) 
public static class AppConfig { 

    @Bean(initMethod = "loadData") 
    public Neo4jLoader dataLoader() { 
     return new Neo4jLoader(); 
    } 

} 

//public class Neo4jRepositoryConfig extends Neo4jConfiguration { 
@EnableTransactionManagement 
@EnableNeo4jRepositories(basePackages = "io.trips.rest.neo4j") 
@Configuration 
public class Neo4jConfig extends Neo4jConfiguration { 

    static final String DB_PATH = "target/neo4j-test-db"; 

    @Bean //(destroyMethod = "shutdown") 
    public EmbeddedGraphDatabase graphDatabaseService() throws IOException { 
     FileUtils.deleteRecursively(new File(DB_PATH)); 
     return new EmbeddedGraphDatabase(DB_PATH); 
    } 

    @Bean 
    public Neo4jTemplate neo4jTemplate() throws IOException { 
     return new Neo4jTemplate(graphDatabaseService()); 
    } 

    @Bean 
    public Neo4jMappingContext neo4jMappingContext() { 
     return new Neo4jMappingContext(); 
    } 

    @Bean 
    public JtaTransactionManagerFactoryBean transactionManager() throws Exception { 
     return new JtaTransactionManagerFactoryBean(graphDatabaseService()); 
    } 

    @Bean 
    public Neo4jExceptionTranslator exceptionTranslator() { 
     return new Neo4jExceptionTranslator(); 
    } 

    /** 
    @Bean(initMethod = "loadData") 
    public Neo4jLoader neo4jLoader() { 
     return new Neo4jLoader(); 
    } 
    */ 
}} 

Organization.java(节点)

@NodeEntity 
public class Organization { 

    @GraphId 
    private Long id; 

    //@Indexed(unique = true, indexName = "Geo") 
    String name; 
} 

Organization.repository

package io.trips.rest.neo4j; 
import org.springframework.data.neo4j.repository.GraphRepository; 
public interface OrganizationRepository extends GraphRepository<Organization> { 
} 

的pom.xml:

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <spring.version>3.2.2.RELEASE</spring.version> 
    <spring.security.version>3.2.0.M1</spring.security.version> 
    <springdata-jpa.version>1.3.1.RELEASE</springdata-jpa.version> 
    <springdata-neo4j.version>2.2.0.RELEASE</springdata-neo4j.version> 
    <springdata-rest-webmvc.version>1.1.0.M1</springdata-rest-webmvc.version> 
    <jackson.version>2.1.2</jackson.version> 
    <slf4j.version>1.7.2</slf4j.version> 
</properties> 

这是一个完整的堆栈跟踪:

+0

删除Neo4jConfig中的neo4jTemplate()方法。它将正确实例化,因为它已经在Neo4jConfiguration中定义。现在会发生什么? – tstorms 2013-05-14 11:04:14

+0

谢谢。但我仍然得到完全相同的错误。 '创建名为'io.trips.rest.WebAppInitializer $ Neo4jConfig'的bean时出错:bean实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化bean类[io.trips.rest.WebAppInitializer $ Neo4jConfig $$ EnhancerByCGLIB $$ a73cba7a]:找不到默认构造函数;嵌套异常是java.lang.NoSuchMethodException:io.trips.rest.WebAppInitializer $ Neo4jConfig $$ EnhancerByCGLIB $$ a73cba7a。 ()' – Tony 2013-05-14 18:08:53

+0

这可能是有用的信息 - neo5j-test-db目录未在目标路径中创建。 – Tony 2013-05-14 19:03:51

回答

2

的解决方案是移动类Neo4jConfig出WebAppInitializer类的。

相关问题