Results 1 to 8 of 8

Thread: lazy-init ignored?

  1. #1
    Join Date
    Jul 2005
    Location
    Munich, Germany
    Posts
    153

    Default lazy-init ignored?

    Hello,

    I'm using Spring 1.2.1 and it seems that the lazy-init attribute for the bean element is being ignored.

    I have defined a bean -

    <bean id="myComponent" class="..." lazy-init="true">
    ...
    </bean>


    But as soon as I start my application, spring initializes this component -

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'myComponent' defined in ServletContext resource [/WEB-INF/conf/app-service.xml]: Initialization of bean failed; nested exception is javax.naming.CommunicationException: Receive timed out

    The exception is thrown because the EJB-Server is currently down...that is why I want the bean to be created lazily, so the Exception itself would be okay.

    The component isn't requested anywhere in my code or config. So why does spring initialize the bean?

    What could be the mistake?


    Best

    Oliver

  2. #2
    Join Date
    Sep 2004
    Posts
    1,086

    Default

    I think lazy-init doesn't work when beans are referenced somewhere inside the context itself.

    What you need is, probably, AbstractSlsbInvokerInterceptor.lookupOnStartup = false.

  3. #3
    Join Date
    Jul 2005
    Location
    Munich, Germany
    Posts
    153

    Default

    Quote Originally Posted by dejanp
    I think lazy-init doesn't work when beans are referenced somewhere inside the context itself.
    The bean isn't referenced somewhere (neither in the context nor at application side). Maybe it's a bug?

    Quote Originally Posted by dejanp
    What you need is, probably, AbstractSlsbInvokerInterceptor.lookupOnStartup = false.
    Mhm. Where should that be set in a servlet based setup?

  4. #4
    Join Date
    Sep 2004
    Posts
    1,086

    Default

    Something like:

    <bean id="myComponent"
    class="org.springframework.ejb.access.LocalStatele ssSessionProxyFactoryBean">
    <property name="jndiName"><value>...</value></property>
    <property name="lookupOnStartup"><value>false</value></property>
    ...
    </bean>

  5. #5
    Join Date
    Jul 2005
    Location
    Munich, Germany
    Posts
    153

    Default

    <bean id="myComponent"
    class="org.springframework.ejb.access.LocalStatele ssSessionProxyFactoryBean">
    <property name="jndiName"><value>...</value></property>
    <property name="lookupOnStartup"><value>false</value></property>
    ...
    </bean>
    Thanks for your reply, but that doesn't work -


    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'myComponent' defined in ServletContext resource [/WEB-INF/conf/app-service.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'lookupOnStartup' of bean class [org.springframework.ejb.access.SimpleRemoteStatele ssSessionProxyFactoryBean]: Bean property 'lookupOnStartup' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
    org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'lookupOnStartup' of bean class [org.springframework.ejb.access.SimpleRemoteStatele ssSessionProxyFactoryBean]: Bean property 'lookupOnStartup' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?

  6. #6
    Join Date
    Sep 2004
    Posts
    1,086

    Default

    lookupHomeOnStartup, not lookupOnStartup, sorry.

  7. #7
    Join Date
    May 2006
    Posts
    3

    Default

    Hi,
    regarding the lazy-init attribute it will get ignored if the bean in which it is used is a referenced one but if u mark the chain of dependent beans as lazy-init set to true it will solve the problem.

  8. #8
    Join Date
    Sep 2006
    Location
    Hong Kong
    Posts
    26

    Default

    Quote Originally Posted by anandr View Post
    Hi,
    regarding the lazy-init attribute it will get ignored if the bean in which it is used is a referenced one but if u mark the chain of dependent beans as lazy-init set to true it will solve the problem.
    It doesn't work for me either. However, at <beans> tag I define as follow:

    <beans default-init-method="initialize">

    Will it make the lazy-init attributes being ignored?

Similar Threads

  1. Hibernate and Lazy Loading.
    By cmrudd in forum Data
    Replies: 1
    Last Post: Oct 3rd, 2005, 03:58 AM
  2. Replies: 4
    Last Post: Jun 20th, 2005, 10:52 AM
  3. init method in HttpServletBean set as final
    By james_a_woods in forum Web
    Replies: 2
    Last Post: Jun 13th, 2005, 07:23 PM
  4. Replies: 4
    Last Post: May 26th, 2005, 05:44 PM
  5. hibernate lazy init error
    By hsantos in forum Data
    Replies: 1
    Last Post: Oct 20th, 2004, 09:36 AM

Posting Permissions

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