Results 1 to 8 of 8

Thread: (Advanced) Bean Configuration

  1. #1
    Join Date
    Nov 2004
    Posts
    4

    Default (Advanced) Bean Configuration

    I would like to use the BeanFactory for a class implementing this interface (I know it wouldn't be a Bean):

    interface MyInterface {

    public void setName(String name) ;

    public void add(DataSource datasource);

    public String put(String key, String value);

    }

    The first one is a property and is no problem.
    But what about the method 2 and 3.
    Is it even possible to do it with a BeanFactory?

    Kindest regards,
    Victor
    The technical we do immediately, the political takes *forever*.

  2. #2
    Join Date
    Aug 2004
    Location
    Toulouse, France
    Posts
    148

    Default

    What do you want to do exactly ?
    just create a bean of this interface ? or set all the values in the configuration of the beanFactory / applicationContext ? In this case, indeed, it is not directly doable and I'd suggest to switch to a real bean with a setDataSourceList(List) and setMap(Map) or eventually only as backup of your real add(DataSource) and put(String,String) to be used at init time

    HTH

    Olivier

  3. #3
    Join Date
    Nov 2004
    Posts
    4

    Default

    E.g. if I have the class
    org.apache.commons.dbcp.BasicDataSource
    and I would like to use the method
    addConnectionProperty(String name, String value) .
    How would I do that?
    Is it really necessary to extend this class to implement convenience methods.
    Somehow this would defeat the purpose to ease my development.

    Kindest regards,
    Victor
    The technical we do immediately, the political takes *forever*.

  4. #4
    Join Date
    Aug 2004
    Location
    Toulouse, France
    Posts
    148

    Default

    Do you really need this method for the BasicDataSource ?
    You can set up a complete one like thid :
    Code:
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
      <property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property>
      <property name="url"><value>jdbc&#58;//my_database</value></property>
      <property name="username"><value>joe</value></property>
      <property name="password"><value>smith</value></property>
    </bean>
    And you have a handful of other setting accessible by normal setters which may cover your needs. Can you describe your needs some more ?

    Olivier

  5. #5
    Join Date
    Nov 2004
    Posts
    4

    Default

    Thanks for the example but what I am looking for is a generic approach to add/put additional properties and this was only an example I found quickly.
    This is a situation that will occur regularly because there are a lot libraries which are not build explicitly out of beans (not necessarily a bad thing).
    Actually this option must exist, at least internally because one can create lists or maps.
    I would like somthing like:
    <bean id="first" class="MyClass">
    <property type="add" name="prop"><value>named add</value></property>
    <property type="add"><value>generic add</value></property>
    <property type="put" name="prop"><value>named</value><value>put</value></property>
    <property type="put"><value>generic</value><value>put</value></property>
    </bean>

    If this or something similar is not possible I would do it on my own but I would hate it to reinvent the wheel.

    Kindest regards,
    Victor
    The technical we do immediately, the political takes *forever*.

  6. #6
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Quote Originally Posted by kromo
    what I am looking for is a generic approach to add/put additional properties
    Maybe MethodInvokingFactoryBean might help you?

    Regards,
    Andreas

  7. #7
    Join Date
    Nov 2004
    Posts
    4

    Default

    That's what I was looking for.
    It's pretty verbose but will do the job.

    Thanks a lot.

    Kindest regards,
    Victor
    The technical we do immediately, the political takes *forever*.

  8. #8
    Join Date
    Aug 2004
    Location
    Toulouse, France
    Posts
    148

    Default

    the MethodInvokingFactoryBean creates a bean off a method invocation but isn't made to initialize a bean with arbitrary method call. It could be used but in a contrived way. Eventually, I would prefer an improvement of the configuration to allow arbitrary methods to be called for init rather than perverting the MethodInvokingFactoryBean.

    Olivier

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 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
  •