Announcement Announcement Module
Collapse
No announcement yet.
customized init method Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment

    Working...
    X