Announcement Announcement Module
Collapse
No announcement yet.
Implementing AutoWire at request. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Implementing AutoWire at request.

    Hello Springers.

    I found the AutoWire capability of the Framework quite appealing when it comes to integrating 3rd party modules, or to wire-up parts of the application built by different members of the team.

    However I did not like the fact, taht I only specify autowiring method, and all the properties will be autowired.

    I was actualy looking for a method of auto-finding beans for specific properties (like the DAO implementor or some support bean).
    Code:
    <bean class="...">
      <property name="daoImplementation" autowire="bytype"/>
    </bean>
    I cold not find anything that could make this work.

    So I thought of another method.

    I decided to implement PropertyPlaceholderConfigurer-like (or even derived from PropertyPlaceholderConfigurer) bean, that will process property values in the form of:
    Code:
    <bean class="...">
      <property name="daoImplementation">$<org.man.dao.IDao></property>
    </bean>
    ...and will search for a bean with that class in the context.

    What do you think? Any pointers?

    Should I start from scratch, and implement a BeanFactoryPostProcessor?
    Or should I just extends PropertyPlaceholderConfigurer and override the parseValue method to resolve string properties to beans in the context?

  • #2
    It's not quite the same thing, but don't forget that if you do specify a value for a property, Spring will not try to autowire it. You can combine this with autowiring by type for objects only, and have a pretty flexible setup where spring fills in all the complex types, you can override any of these you think might be a problem (there are two of them, etc.), and you manually provide values for all the scalar types (integers, etc.)

    Comment


    • #3
      Originally posted by Colin Sampaleanu
      It's not quite the same thing, but don't forget that if you do specify a value for a property, Spring will not try to autowire it.
      Yes, I am aware of that, but I think the more common situation is wiring a couple of properties, than setting explicitly a couple and autowiring all other.

      I want to be able from 20 properties to set 2 and autowire another 2.

      Originally posted by Colin Sampaleanu
      You can combine this with autowiring by type for objects only, and have a pretty flexible setup where spring fills in all the complex types, you can override any of these you think might be a problem (there are two of them, etc.), and you manually provide values for all the scalar types (integers, etc.)
      I did not get this. Override what? Autowiring types? How? Where? Docs?

      Comment


      • #4
        All I meant by overriding was that if you think the autowiring for a property is not going to work (will be ambiguous, etc.) you can set it explicitly.

        In any case, right now you can not have the setup where for 20 complex properties, you set 2 of them explicitly, spring autowires 2 of them, and the rest of them are left alone.

        You might want to file a feature request in Jira...

        Comment


        • #5
          Originally posted by Colin Sampaleanu
          All I meant by overriding was that if you think the autowiring for a property is not going to work (will be ambiguous, etc.) you can set it explicitly.
          I understand, but my problem is that the service is provided by other party.
          I mean: DAO implementation party and ServiceImplementation party.
          They both supply modules, and I have to wire them, or (what I want to do), both parties specify injections (by setting the properties to autowire) for those connection points. And the autowirer does the post-production linkage.

          Originally posted by Colin Sampaleanu
          In any case, right now you can not have the setup where for 20 complex properties, you set 2 of them explicitly, spring autowires 2 of them, and the rest of them are left alone.
          You might want to file a feature request in Jira...
          I am not aware of the time line that such a request will be evaluated/solved/implemented. I also can put some brain muscle to the problem, if it is not propostrous.

          Comment

          Working...
          X