我有以下课程
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:my-ctx.xml"})
public class UserTests {
@Inject
private ApplicationContext applicationContext;
private UserRepository getUserRepository() {
return (UserRepository)applicationContext.getBean("userRepository", CrudRepository.class);
}
@Test
public void someTest() {
User user = new User();
user.setName("John Doe");
getUserRepository().save(user);
}
}
运行测试,我收到以下错误
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': FactoryBean threw exception on object creation; nested exception is java.lang.NullPointerException
...
根本原因是
org.datanucleus.api.jpa.metamodel.SingularAttributeImpl.isVersion(SingularAttributeImpl.java:79)
org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.findVersionAttribute(JpaMetamodelEntityInformation.java:92)
org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.<init>(JpaMetamodelEntityInformation.java:78)
org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getMetadata(JpaEntityInformationSupport.java:65)
org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:146)
org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:84)
org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:67)
...
哪里VersionMetaData vermd = mmd.getAbstractClassMetaData().getVersionMetaData();
是空的。
这是一个错误吗?
我知道我可以放类似的东西@Inject UserRepository userRepository;
,但是考虑到 Spring Data 的工作原理,这两个应该有相同的结果,对吧?无论如何,结果将是相同的错误。
我正在使用 Spring 数据 1.4.1、DataNucleus 3.3.2、Spring 3.2.4。