• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Dependency injection problem

 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an application with Spring framework, using AnnotationSessionFactoryBean. I'm also using Hibernate.



The problem is boReporte is not being instantiated by Spring. If before the problem line I add this:

the application continues to run and the DAO class is instantiated normally in my BO. I don't understand why this happens. I also don't understand why I have to set hibernate's session factory via code, I wasn't able to do it via my applicationContext.xml, which contains the sessionFactory mentioned in the code above.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It'd be handy to include the config file.
 
Eduardo Bueno
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here it is:
 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why there is no boReporte in application context file?
 
Eduardo Bueno
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why there should be? As far as I know, @Component annotation means the class will be auto-detected when using annotation-based configuration.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you need to add the bean names to the Annotations?

Did you check to see what exceptions were thrown, in the logs?

For the Hibernate stuff, why are you using "Annotated Packages" They are not used to find Entities. Most people think that that property is for that, but it isn't.

Someone actually had to extend the class so that you can state what package your Entities reside in so you don't have to list out each and every entity class in your xml.
http://baldercm.blogspot.com/2008/06/howto-setup-spring-for-hibernate.html

they actually plan on added that in Spring 3.x

But for your issue, i know there had to be an exception thrown and we need to see what that it, that will tell us why Spring either missed the class, or had a problem with something.

So it might be in your Tomcat console or Tomcat log.

Mark
 
Eduardo Bueno
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I had an error in my application. I was instantiating ReporteService with new(), that's why BO was null. If I remove it the application still doesn't run, I get a NullPointerException in my getReporteService method in my pageBean. Again, if I try to use it works. The main problem is, why do I have to use the context to instantiate my beans, at some moment? Wasn't it supposed to be Spring's task?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to get a class through Spring if you expect Spring to be able to do anything with/to it, like set properties etc.

If you instantiate a class with "new" then Spring has no way of knowing it was instantiated--Spring's not involved in core Java.
 
Drove my Chevy to the levee but the levee was dry. A wrung this tiny ad and it was still dry.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic