0

I need to wire a property for a given object without using a bean id, if possible. Autowiring doesn't work, because the type of the property is Object and is, hence, not specific at all. Is there a way to autowire by class or interface like this:

<bean class="NonSpecificClassThing">
    <property name="targetObject">
        <a:wire-by-type type="com.things.MyInterface"/>
    </property>
</bean>

<bean class="com.things.MyInterfaceImpl"/>

Is something like this possible?

1 Answer 1

1

Apparently you can do something like this :

target class :

public class NonSpecificClassThing {

      private Object targetObject;

      // do something;

      public getTargetObject() {
         return targetObject;
      } 

      public void setTargetObject(Object targetObject) {
         this.targetObject = targetObject;
      }
}

spring context :

<bean class="NonSpecificClassThing">
    <property name="targetObject">
        <ref bean="com.things.MyInterfaceImpl"/>
    </property>
</bean>

<bean class="com.things.MyInterfaceImpl"/>
3
  • They reference the same object? Jul 27, 2012 at 20:29
  • Can you provide a link to how this works? For instance, what if the com.things.MyInterfaceImpl bean is more configured? Jul 27, 2012 at 20:31
  • @TK Kocheran I've edited my answer. What do you mean by more configured ? To have other bean injected into it ? Jul 27, 2012 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.