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>
這是一個完整的堆棧跟蹤:
刪除Neo4jConfig中的neo4jTemplate()方法。它將正確實例化,因爲它已經在Neo4jConfiguration中定義。現在會發生什麼? – tstorms 2013-05-14 11:04:14
謝謝。但我仍然得到完全相同的錯誤。 '創建名爲'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
這可能是有用的信息 - neo5j-test-db目錄未在目標路徑中創建。 – Tony 2013-05-14 19:03:51