Announcement Announcement Module
Collapse
No announcement yet.
lazy-init ignored? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    I think lazy-init doesn't work when beans are referenced somewhere inside the context itself.

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

    Comment


    • #3
      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?

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

      Comment


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

        Comment


        • #5
          <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?

          Comment


          • #6
            lookupHomeOnStartup, not lookupOnStartup, sorry.

            Comment


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

              Comment


              • #8
                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?

                Comment

                Working...
                X