Spring Data Commons
  1. Spring Data Commons
  2. DATACMNS-133

Documented Configuration of Conversion Service with DomainClassConverter Does Not Work

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.2.1, 1.3 M1
    • Fix Version/s: 1.3 RC1
    • Component/s: Core, Documentation
    • Labels:
      None
    • Environment:
      spring-data-commons-core 1.2.0.RELEASE on the classpath.

      Description

      The Spring Data JPA documentation describes configuring a DomainClassConverter like so:

      <mvc:annotation-driven conversion-service="conversionService" />
      
      <bean id="conversionService" class="....context.support.ConversionServiceFactoryBean">
        <property name="converters">
          <list>
            <bean class="org.springframework.data.repository.support.DomainClassConverter">
              <constructor-arg ref="conversionService" />
            </bean>
          </list>
        </property>
      </bean>
      

      However, this fails to work from an apparent cyclic instantiation error ("Error creating bean with name 'conversionService': FactoryBean which is currently in creation returned null from getObject").

      This is one workaround for the problem:

      <bean id="conversionService" class="org.springframework.core.convert.support.DefaultConversionService"/>
      
      <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetClass" value="org.springframework.core.convert.support.ConversionServiceFactory"/>
        <property name="targetMethod" value="registerConverters"/>
        <property name="arguments">
          <util:list>
            <set>
              <bean class="org.springframework.data.repository.support.DomainClassConverter">
                <constructor-arg ref="conversionService"/>
              </bean>
            </set>
            <ref bean="conversionService"/>
          </util:list>
        </property>
      </bean>
      

        Issue Links

          Activity

          Hide
          Oliver Gierke added a comment -

          Pushed and deployed the necessary changes to DomainClassConverter. You should now be able to simply declare the converter as follows:

          <bean class="....DomainClassConverter">
            <constructor-arg ref="conversionService" />
          </bean>
          
          <bean id="conversionService" class="....ConversionServiceFactoryBean" />
          

          The custom class is not necessary as of the snapshot deployment.

          Show
          Oliver Gierke added a comment - Pushed and deployed the necessary changes to DomainClassConverter . You should now be able to simply declare the converter as follows: <bean class= "....DomainClassConverter" > <constructor-arg ref= "conversionService" /> </bean> <bean id= "conversionService" class= "....ConversionServiceFactoryBean" /> The custom class is not necessary as of the snapshot deployment.
          Hide
          Joelton Flores added a comment -

          Seems still not resolving the beans from parent context on the DomainClassConverter. Would this work?

          Instead of:
          CrudRepository<Object, Serializable> repository = BeanFactoryUtils.beanOfType(context, objectType);

          To:
          CrudRepository<Object, Serializable> repository = BeanFactoryUtils.beanOfTypeIncludingAncestors(context, objectType);

          Show
          Joelton Flores added a comment - Seems still not resolving the beans from parent context on the DomainClassConverter. Would this work? Instead of: CrudRepository<Object, Serializable> repository = BeanFactoryUtils.beanOfType(context, objectType); To: CrudRepository<Object, Serializable> repository = BeanFactoryUtils.beanOfTypeIncludingAncestors(context, objectType);
          Hide
          Oliver Gierke added a comment -

          Good catch, fixed and deployed to 1.3.0.BUILD-SNAPSHOT.

          Show
          Oliver Gierke added a comment - Good catch, fixed and deployed to 1.3.0.BUILD-SNAPSHOT.
          Hide
          Patrick Dumontel added a comment -

          I have tried this with the JPA 1.1.0.RELEASE and commons 1.3.0.RELEASE and the workaround is still needed

          Show
          Patrick Dumontel added a comment - I have tried this with the JPA 1.1.0.RELEASE and commons 1.3.0.RELEASE and the workaround is still needed
          Hide
          Oliver Gierke added a comment -

          Please do not re-open issues assigned to already released versions. File a new ticket instead. Which workaround are you refering to?

          Show
          Oliver Gierke added a comment - Please do not re-open issues assigned to already released versions. File a new ticket instead. Which workaround are you refering to?

            People

            • Assignee:
              Oliver Gierke
              Reporter:
              Mike Whittemore
            • Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 3h Original Estimate - 3h
                3h
                Remaining:
                Time Spent - 0.5h Remaining Estimate - 3h
                3h
                Logged:
                Time Spent - 0.5h Remaining Estimate - 3h
                0.5h