This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Do I need to use Spring MVC in this case?

 
Mike London
Ranch Hand
Posts: 1190
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some Spring beans I need to wire and make available in a web application. I was hoping to just use a regular Java Http Servlet and wire up my Spring beans and then access the wired beans from the regular Java Servlet.

However, now that I've got the DispatcherServlet wired and Spring says it's setup all my beans, when I try to use the beans from a regular Servlet, none of the beans are wired. I'm getting NullPointerExceptions for properties not injected.

Therefore, when you use DispatcherServlet, is it then necessary to use Spring-MVC to then be able to access the wired beans you've set up or can I access them in a regular Servlet I've defined? So far, the regular Servlet route doesn't appear to work and, in the debugger, there aren't any obvious "context" objects.

Maybe I'm answering my own question here, but I'm not quite sure if there isn't a slick way to access the wired beans without full-blown MVC. I don't need a form. I just need to return a value from a wired bean that connects to other beans, etc., in a web context.

Thanks in advance for any replies.

- mike
 
Mike London
Ranch Hand
Posts: 1190
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved. Yes, needed MVC.
 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You already have your answer, but hopefully I can provide an explanation Autowiring only works in spring loaded beans. The way autowiring works is that during the bean initialization process, spring inspects each bean it initializes for autowiring annotations. If it finds them , it wires them. If spring hasn't loaded the object, it can't autowire into it. THe only way (that I know of) to have autowiring into your web layer is to use Spring MVC. When you use Spring MVC, Spring initializes the controller beans, and that allows it to do autowiring into it
 
Mike London
Ranch Hand
Posts: 1190
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jayesh A Lalwani wrote:You already have your answer, but hopefully I can provide an explanation Autowiring only works in spring loaded beans. The way autowiring works is that during the bean initialization process, spring inspects each bean it initializes for autowiring annotations. If it finds them , it wires them. If spring hasn't loaded the object, it can't autowire into it. THe only way (that I know of) to have autowiring into your web layer is to use Spring MVC. When you use Spring MVC, Spring initializes the controller beans, and that allows it to do autowiring into it


I very much appreciate your reply to my posting.

Thanks again.

mike
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic