我正在尝试将我的项目移动到Spring Boot 2.0.0.M2和Spring Data Neo4j 5.0.0.M4。
在Maven类路径上,我有以下工件:
这是我以前的Spring Data Neo4j配置:
1.Bolt Driver
import org.neo4j.ogm.drivers.bolt.driver.BoltDriver;
import org.neo4j.ogm.service.Components;
import org.neo4j.ogm.session.SessionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
import org.springframework.data.neo4j.transaction.Neo4jTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Profile("production")
@Configuration
@EnableNeo4jRepositories(basePackages = "com.example.domain.repository.neo4j")
@EnableTransactionManagement
public class Neo4jConfig {
@Value("${neo4j.server.database.uri}")
private String serverDatabaseUri;
@Value("${neo4j.username}")
private String username;
@Value("${neo4j.password}")
private String password;
@Bean
public Neo4jTransactionManager transactionManager() throws Exception {
return new Neo4jTransactionManager(sessionFactory());
}
@Bean
public SessionFactory sessionFactory() {
Components.setDriver(new BoltDriver());
return new SessionFactory(configuration(), "com.example.domain.model.neo4j");
}
@Bean
public org.neo4j.ogm.config.Configuration configuration() {
org.neo4j.ogm.config.Configuration configuration = new org.neo4j.ogm.config.Configuration();
// @formatter:off
configuration
.autoIndexConfiguration()
.setAutoIndex("assert");
configuration
.driverConfiguration()
.setCredentials(username, password)
.setURI(serverDatabaseUri);
// @formatter:on
return configuration;
}
}
2。嵌入式驱动程序(对于我的测试)
@Profile("test")
@Configuration
@EnableNeo4jRepositories(basePackages = "com.example.domain.repository.neo4j")
@EnableTransactionManagement
public class Neo4jTestConfig {
@Value("${neo4j.embedded.database.path}")
private String storeDir;
@Bean
public Neo4jTransactionManager transactionManager() throws Exception {
return new Neo4jTransactionManager(sessionFactory());
}
@Bean
public SessionFactory sessionFactory() {
org.neo4j.ogm.config.Configuration configuration = new org.neo4j.ogm.config.Configuration();
// Register your configuration here, this will confuse OGM so the driver you set below won't be destroyed
Components.configure(configuration);
// Register your driver
EmbeddedDriver driver = new EmbeddedDriver(graphDatabaseService());
Components.setDriver(driver);
// Set driver class name so you won't get NPE
configuration.driverConfiguration().setDriverClassName("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver");
// Configure auto index
configuration.autoIndexConfiguration().setAutoIndex("assert");
return new SessionFactory(configuration, "com.example.domain.model.neo4j");
}
@Bean(destroyMethod = "shutdown")
public GraphDatabaseService graphDatabaseService() {
// @formatter:off
GraphDatabaseService graphDatabaseService = new GraphDatabaseFactory()
.newEmbeddedDatabaseBuilder(new File(storeDir))
.loadPropertiesFromFile(this.getClass().getClassLoader().getResource("neo4j.properties").getPath())
.newGraphDatabase();
// @formatter:on
return graphDatabaseService;
}
}
现在我遇到了以下问题:
1. Components cannot be resolved
2. The constructor Configuration()
3. The method autoIndexConfiguration() is undefined for the type Configuration
4. The method driverConfiguration() is undefined for the type Configuration
如何正确实施Spring Data Neo4j 5.0.0.M4
的这些配置?