• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Spring autowired

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have one question on spring beans dependency injection.

I have one bean which needs to be loaded during startup and inside this bean i have one dependency bean which i want to load during the first request.

so i made the lazy-init true for that bean. but because of @autowired annotation when first bean is loaded it tries to find the dependency bean which is not available in the contained(lazy loading is set true).

so how can i inject this dependency to load during first request ?

suggest me except Application context /bean factory loading

Thank you in advance
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By definition an eagerly loaded bean can not have dependencies on a lazy one or it will nullify the lazy load. My first question is can you describe why the need for lazy loading? Lazy loading is often misused and I would take a close look at if that is the best solution, it is even more suspicious since you have a bean that you apparently think needs to be eager yet has a dependency on the lazy. Most likely something is wrong with your dependencies or that bean should not really be lazy in the first place.

Assuming lazy loading does make sense, you can look here for one work around.
http://forum.springsource.org/showthread.php?124290-Spring-Annotations-Lazy-Autowired
 
karibasappa Guttur Chikkaveerappa
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bill,

I know about what you explained, but my requirement is like that.

i am loading all the beans through package using context:component-scan and in that one bean has dependency on lazy loading bean. so i want that dependency to lazy load it.

because lazy loading bean is calling rmi, but i dont want this bean to load during application start-up, it should load during call to rmi in the code...
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
lazy load should be reserved for very expensive initialization scenarios which make sense to put off. If you think about it, usually it makes more sense to pay the piper at startup then at runtime when a request comes in, unless of course it is unlikely that request will ever come. If start-up performance is a huge concern you may want to consider lazy loaded beans. Another disadvantage of them, is that if something goes wrong during initialization you will not know at start-up but rather it may pop up hours, days or weeks later. I can count the number of times I have used lazy initialized beans on one hand.

That said with RMI (I assume you are using Spring for this) have a look at the lookupStubOnStartup property of the RmiProxyFactoryBean. Try setting it to false.

 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is a link (copy and paste it into the browser rather than click it. Seems to leave out the last ) for me otherwise)
http://static.springsource.org/spring/docs/3.2.x/javadoc-api/org/springframework/remoting/rmi/RmiClientInterceptor.html#setLookupStubOnStartup(boolean)
 
karibasappa Guttur Chikkaveerappa
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya you are correct, i set it false and its working fine as expected.

Thanks.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am having the same issue. I tired setting lookup-home-on-startup="false", it did solves the initialization issue.
However, when my client tries to call the remote server, it encounters an error: No EJB receiver available for handling combination for invocation context.
By setting the above to true, it will work.
Any idea how to resolve this?
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This sounds JBOSS related more than Spring. Try creating a topic clearly specifying your configuration and what you are trying to do in our JBOSS forums.
 
reply
    Bookmark Topic Watch Topic
  • New Topic