Results 1 to 2 of 2

Thread: customized init method

  1. #1
    Join Date
    Aug 2004
    Posts
    22

    Default customized init method

    Hi,

    I'm interested in migrating our current services framework which is based on IBM WebSphere PortletServices concept. Basically all services implement the PortletServiceProvider interface which implements two lifecycle methods:

    init(PortletServiceConfig config)
    destroy()

    I see from the reference guide how to add a normal no-args init method, but what would I need to do to add the init method listed above?

    Also, in our model our services descriptor supports a <load-on-startup>true/false</load-on-startup> setting. basically this allows the service factory to either init() the service at load time if true or only when the service is first accessed if false (corresponding to factory.getBean(...) in Spring). How can I continue to support this?

    Thanks, Jason

  2. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    The destroy() method can be called by adding a destroy-method attribute to your bean definition.

    Using lazy-init (defined on bean definition level) you can tell the BeanFactory to wait with instantiating your bean until it is actually loaded. You can only apply the lazy-init parameter to singletons however.

    As for the PortletConfig, there is no way you can do this without writing some custom code (which is reusable for all PortletServices however).

    Implement a BeanFactoryPostProcessor and add it to your application context. At startup time (of the context) it will automatically be detected and given the chance to do post processing of beans in the application context.

    For example:

    Code:
    public void postProcessBeanFactory&#40;ConfigurableListableBeanFactory fact&#41; &#123;
      Map m = fact.getBeansOfType&#40;PortletServiceProvider.class, false, false&#41;;
      Iterator it = m.keySet&#40;&#41;.iterator;
      // iterate over beans and invoke the init&#40;PortletConfig&#41; method
    &#125;
    There is one thing however; you won't be able to combine a lazily initializing bean with the BeanFactoryPostProcessor. Maybe somebody else has a solution for this?

    Alef

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. PerformanceMonitorInterceptor
    By tnist in forum AOP
    Replies: 3
    Last Post: Aug 24th, 2005, 01:39 PM
  5. Replies: 1
    Last Post: Jul 28th, 2005, 05: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
  •