ClassNotFoundException org.neo4j.graphdb.factory.GraphDatabaseFactory

6 浏览
0 Comments

ClassNotFoundException org.neo4j.graphdb.factory.GraphDatabaseFactory

我正在尝试测试我的API项目。我遇到了这个问题:

Caused by: java.lang.ClassNotFoundException: org.neo4j.graphdb.factory.GraphDatabaseFactory
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 147 more

有人遇到过这个问题吗?

从问题SpringBoot - BeanDefinitionOverrideException: Invalid bean definition中我知道我需要激活bean覆盖,所以我已经激活了它。

@RunWith(SpringRunner.class)
@SpringBootTest(properties = "spring.main.allow-bean-definition-overriding=true")
@ContextConfiguration(classes = { TestConfiguration.class})
@ActiveProfiles(profiles = "test")
public class EmployeeRepositoryTest {
    @Autowired
    private EmployeeService employeeService;
    @Test
    public void testIt() {
        Employee user = new Employee(10, "Test");
        employeeService.addEmployee(user);
        Iterable allEmp = employeeService.findAll();
        assertThat(allEmp).hasSize(1);
    }
}

这是我的配置类:

@Configuration
@EnableTransactionManagement
@ComponentScan(basePackages = { "com.neo4j.interview.api" })
@EnableNeo4jRepositories(basePackages = "com.neo4j.interview.api.repository")
@Profile({ "embedded", "test" })
public class TestConfiguration {
    @Bean
    public org.neo4j.ogm.config.Configuration getConfiguration() {
        org.neo4j.ogm.config.Configuration config = new Builder().build();
        return config;
    }
    @Bean()
    public SessionFactory sessionFactory() {
        return new SessionFactory(getConfiguration(), "com.neo4j.interview.api.domain");
    }
    @Bean
    public Neo4jTransactionManager transactionManager() {
        return new Neo4jTransactionManager(sessionFactory());
    }
}

这是我的pom.xml:



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.2.5.RELEASE
         
    
    com.neo4j.interview.api
    neo4jtestapi
    0.0.1-SNAPSHOT
    neo4jtestapi
    Neo4j test project API
    
        UTF-8
        UTF-8
        11
        4.0.2
        1.2.17
    
    
        // 依赖列表
    
    
        // 构建配置
    

更新:

如果我移除覆盖行,EmployeeRepositoryTest中的employeeService将为null。

0