Announcement Announcement Module
Collapse
No announcement yet.
Custom property editor doesn't fire in new version of spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom property editor doesn't fire in new version of spring

    I have an application context and registered custom editor.
    When application starts and bean factory is initialized custom editor is called for bean creation but when later in application i create the bean with beanFactory.getBean("beanName") it is not called. spring-2.0 calls it in both cases. Is it a new feature or bug?

  • #2
    Depends on your code

    Comment


    • #3
      Is it possible to see what you were trying to do?

      Comment


      • #4
        It is registered in the following way
        <bean class="org.springframework.beans.factory.config.Cu stomEditorConfigurer">
        <property name="customEditors">
        <map>
        <entry key="java.lang.String">
        <bean class="com.my.CustomEditor"/>
        </entry>
        </map>
        </property>
        </bean>
        Later the following code gets bean from context
        Object target = targetsMap.get(targetSelector);
        if (target == null) {
        target = beanFactory.getBean(targetName);
        }
        and editor fires only the first time.
        The bean is prototype. In spring-2.0.4 it fires but in 2.0.6 - no.
        Last edited by zaplitny; Oct 28th, 2007, 07:51 AM.

        Comment


        • #5
          BeanWrapperImpl :

          spring-2.0.3 : Object convertedValue = this.typeConverterDelegate.convertIfNecessary(oldV alue, newValue, pd);

          spring-2.0.6 : Object convertedValue = (propertyValue.isConverted() ? pv.getConvertedValue() :
          this.typeConverterDelegate.convertIfNecessary(oldV alue, pv.getValue(),pd));

          propertyValues for bean with current name are taken from map, and when it is taken after bean creation, its propertyValue.converted = true
          It means that I cannot generate dynamic propertyValues with propertyEditor. Is there another way of doing this?

          Comment


          • #6
            Originally posted by zaplitny View Post
            It means that I cannot generate dynamic propertyValues with propertyEditor.
            What does that mean? Where do you need/want dynamic property values? And in which way are they dynamic?

            You should also consider using PropertyEditorRegistrar.

            Joerg

            Comment


            • #7
              There are many databases for application and I need to create different datasources that depends on user. For the purpose I set db url in placeholder that looks like jdbc:jtds:sqlserver://server:1433;DatabaseName=#{default} and #{default} is handled by custom editor - it puts there database name or default value. In new version of spring it fires only first time and doesn't change next times

              Comment


              • #8
                Originally posted by zaplitny View Post
                In new version of spring it fires only first time and doesn't change next times
                Which makes kind of sense and was probably changed for optimization reasons. Spring does not expect any change in the config anyway. And you kind of misuse the property editors.

                What you actually should have a look at is the AbstractRoutingDataSource. The original use case is probably not working for you since it needs to know all data sources beforehand. But it seems to be pretty easy to build your own routing data source based on dynamic parameter.

                Joerg

                Comment

                Working...
                X