将spring-data-neo4j 3.2.3升级到3.3.1数据转换失败

时间:2015-08-10 01:48:54

标签: java spring neo4j spring-data spring-data-neo4j

我编写了一个Spring Boot应用程序(V 1.2.5),它使用Spring Data(V 3.2.3)访问Neo4j数据库(V 2.2.1)。

我尝试升级到Spring Data(V 3.3.2),但是当我这样做时,我向neo4jConversionService注册的数据转换不再起作用。应用程序将编译,但任何需要这些转换的调用都会失败。

稍微缩写的堆栈跟踪如下:

15:45:05.341 [http-nio-8080-exec-3] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing
failed; nested exception is org.springframework.data.neo4j.mapping.PersistentEntityConversionException: Requested a entity of type 'class com.eulersbridge.iEngage.database.domain.Owner', but
 the entity is of type 'class com.eulersbridge.iEngage.database.domain.NewsArticle'.] with root cause
org.springframework.data.neo4j.mapping.PersistentEntityConversionException: Requested a entity of type 'class com.eulersbridge.iEngage.database.domain.Owner', but the entity is of type 'clas
s com.eulersbridge.iEngage.database.domain.NewsArticle'.
        at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.read(Neo4jEntityConverterImpl.java:94) ~[spring-data-neo4j-3.3.2.RELEASE.jar:na]
        at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedConverter.read(Neo4jEntityPersister.java:170) ~[spring-data-neo4j-3.3.2.RELEASE.jar:na]
        at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.createEntityFromState(Neo4jEntityPersister.java:189) ~[spring-data-neo4j-3.3.2.RELEASE.jar:na]
        at org.springframework.data.neo4j.support.Neo4jTemplate.createEntityFromState(Neo4jTemplate.java:224) ~[spring-data-neo4j-3.3.2.RELEASE.jar:na]
        at org.springframework.data.neo4j.repository.AbstractGraphRepository.createEntity(AbstractGraphRepository.java:62) ~[spring-data-neo4j-3.3.2.RELEASE.jar:na]
        at org.springframework.data.neo4j.repository.AbstractGraphRepository.findOne(AbstractGraphRepository.java:132) ~[spring-data-neo4j-3.3.2.RELEASE.jar:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_05]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_05]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_05]
        at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_05]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:414) ~[spring-data-commons-1
.10.0.RELEASE.jar:na]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:399) ~[spring-data-commons-1.10.0.R
ELEASE.jar:na]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:371) ~[spring-data-commons-1.10.0.REL
EASE.jar:na]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
        at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61) ~[spring-data-commons-1.10.0.RELEASE.jar:na]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
        at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.1.7.RELEASE.jar:4.1.7.RELEASE]
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) ~[spring-tx-4.1.7.RELEASE.jar:4.1.7.RELEASE]
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.1.7.RELEASE.jar:4.1.7.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
        at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ~[spring-tx-4.1.7.RELEASE.jar:4.1.7.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
        at com.sun.proxy.$Proxy119.findOne(Unknown Source) ~[na:na]
        at com.eulersbridge.iEngage.core.services.LikesEventHandler.checkParams(LikesEventHandler.java:106) ~[classes/:na]

注册转换器的代码(在升级之前工作):

    @Bean protected ConversionService neo4jConversionService() throws Exception
{
    ConversionService conversionService = super.neo4jConversionService();
    ConverterRegistry registry = (ConverterRegistry) conversionService;
    registry.addConverter(new EventToOwnerConverter());
    registry.addConverter(new NewsArticleToOwnerConverter());
    registry.addConverter(new PhotoAlbumToOwnerConverter());
    registry.addConverter(new UserToOwnerConverter());
    registry.addConverter(new CandidateToOwnerConverter());
    registry.addConverter(new TicketToOwnerConverter());

    return conversionService;
}

application.java以更完整的形式:

@PropertySource("classpath:application.properties")
@Configuration
@ComponentScan
@EnableNeo4jRepositories("com.eulersbridge.iEngage.database.repository")
@EnableTransactionManagement(mode = AdviceMode.PROXY)
@EnableAutoConfiguration
@EnableAspectJAutoProxy
public class Application extends Neo4jConfiguration
{
@Resource
private PropertyResolver propResolver;

    private static Logger LOG = LoggerFactory.getLogger(Application.class);

    public static void main(String[] args) 
    {
    if (LOG.isDebugEnabled()) LOG.debug("main()");
    SpringApplication app=new SpringApplication(Application.class);
    app.setShowBanner(false);
    app.run(args);
    }

Application()
{
    setBasePackage("com.eulersbridge.iEngage.database.domain");
}

@Bean(destroyMethod = "shutdown")
public GraphDatabaseService graphDatabaseService() throws IOException
{
    String url=propResolver.getRequiredProperty("neo4j.server.url");
    if (LOG.isDebugEnabled()) LOG.debug("url = "+url);
    return new SpringCypherRestGraphDatabase(url);
}

@Override
    public MappingInfrastructureFactoryBean mappingInfrastructure() throws Exception {
        MappingInfrastructureFactoryBean mapping = super.mappingInfrastructure();
        mapping.afterPropertiesSet();
        return mapping;
    }
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() 
{
   return new PropertySourcesPlaceholderConfigurer();
}

@Bean
public PermissionEvaluator permissionEvaluator()
{
    UserPermissionEvaluator bean= new UserPermissionEvaluator();
    return bean;

}

@Bean protected ConversionService neo4jConversionService() throws Exception
{
    ConversionService conversionService = super.neo4jConversionService();
    ConverterRegistry registry = (ConverterRegistry) conversionService;
    registry.addConverter(new EventToOwnerConverter());
    registry.addConverter(new NewsArticleToOwnerConverter());
    registry.addConverter(new PhotoAlbumToOwnerConverter());
    registry.addConverter(new UserToOwnerConverter());
    registry.addConverter(new CandidateToOwnerConverter());
    registry.addConverter(new TicketToOwnerConverter());

    return conversionService;
}

@Primary
@Bean
public ObjectMapper objectMapper()
{
    ObjectMapper om=new ObjectMapper();
    om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
    return om;
}   
}

Maven依赖项是:

<parent>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.5.RELEASE</version>
    <groupId>org.springframework.boot</groupId>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-aop</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
    </dependency>
    <dependency>
        <groupId>net.sf.supercsv</groupId>
        <artifactId>super-csv</artifactId>
        <version>2.2.0</version>
    </dependency>
    <dependency>
        <groupId>net.sf.supercsv</groupId>
        <artifactId>super-csv-dozer</artifactId>
        <version>2.2.0</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j</artifactId>
        <version>3.3.2.RELEASE</version>
        <exclusions>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aspects</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j-rest</artifactId>
        <version>3.3.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-commons</artifactId>
        <version>1.10.0.RELEASE</version>
    </dependency>
    <dependency>
         <groupId>org.hibernate</groupId>
         <artifactId>hibernate-validator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.hateoas</groupId>
        <artifactId>spring-hateoas</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.plugin</groupId>
        <artifactId>spring-plugin-core</artifactId>
    </dependency>
<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>javax.mail-api</artifactId>
    </dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-velocity</artifactId>
</dependency>
<dependency>
       <groupId>javax.mail</groupId>
       <artifactId>mail</artifactId>
       <version>1.4.7</version>
 </dependency>
<dependency>
    <groupId>com.jayway.jsonpath</groupId>
    <artifactId>json-path</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>com.jayway.jsonpath</groupId>
    <artifactId>json-path-assert</artifactId>
    <version>0.9.1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-kernel</artifactId>
    <version>2.2.1</version>
    <type>test-jar</type>
    <scope>test</scope>
</dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-core</artifactId>
        <version>1.0.59</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-jbehave</artifactId>
        <version>1.0.23</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>commons-validator</groupId>
        <artifactId>commons-validator</artifactId>
        <version>1.4.1</version>
    </dependency>
</dependencies>

有人能指出Spring Data V 3.2和V 3.3之间的变化会导致转换服务不再有效吗?

干杯,

格雷格

0 个答案:

没有答案