This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dependency injection problem

 
Eduardo Bueno
Ranch Hand
Posts: 155
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It'd be handy to include the config file.
 
Eduardo Bueno
Ranch Hand
Posts: 155
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here it is:
 
Hong Anderson
Ranch Hand
Posts: 1936
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why there is no boReporte in application context file?
 
Eduardo Bueno
Ranch Hand
Posts: 155
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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: 155
  • 0
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic