0
我有下面的類春數據錯誤
@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。