Results 1 to 5 of 5

Thread: How can I wire a Class Type property

  1. #1
    Join Date
    May 2005
    Posts
    2

    Default How can I wire a Class Type property

    It is a simple problem that when there is a type Class property(not an instance) in my class, but I don't know how to write in ApplicationContext.xml for this class to use Setter Injection.

    public Class Example{

    private Class member;

    public void setMember(Class member) {
    .....
    }
    .....
    }

    Thanks!
    [/b]

  2. #2
    Join Date
    Mar 2005
    Posts
    3

    Default

    This might work..

    <bean id="exampleclass" class="...Example" >
    <property name="member"> <ref bean="bean_id_for_member_class"/></property>
    </bean>

    You would you need to create an instance of some class in the context with id = "bean_id_for_member_class"

    Just curious .. why do you need to do create a member of type "Class" ? why not just the Object of the specific Class ?

  3. #3
    Join Date
    May 2005
    Posts
    2

    Default

    Sorry, but what you say doesn't work, the key of the problem is that I can't create a Class instanse by Spring's XML.

  4. #4
    Join Date
    Oct 2004
    Location
    Herndon, VA, US
    Posts
    648

    Default

    Try something along the line of:
    Code:
    <bean id="theClassToLoad" class="java.lang.Class" factory-method="forName">
    <constructor-arg value="the.class.to.load"/>
    </bean>
    --Jing Xue

  5. #5
    Join Date
    May 2005
    Location
    London, UK
    Posts
    21

    Default

    Here's a simpler example:
    Code:
    <beans>  
      <bean id="example" class="Example">
        <property name="member"><value>com.foo.Bar</value></property>
      </bean>
    </beans>
    An ApplicationContexts automatically registers a ClassEditor that populates a Class property from a string; "com.foo.Bar" in this case.

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Unit testing with JOTM and JtaTransactionManager
    By lalle in forum Architecture
    Replies: 1
    Last Post: Oct 15th, 2005, 09:05 AM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. Replies: 4
    Last Post: Aug 17th, 2005, 04:42 AM
  5. Replies: 1
    Last Post: Apr 13th, 2005, 10:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •