aspose file tools*
The moose likes Spring and the fly likes Do I need to use Spring MVC in this case? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Do I need to use Spring MVC in this case?" Watch "Do I need to use Spring MVC in this case?" New topic
Author

Do I need to use Spring MVC in this case?

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1075
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

Joined: Jul 12, 2002
Posts: 1075
Solved. Yes, needed MVC.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2435
    
  28

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

Joined: Jul 12, 2002
Posts: 1075
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Do I need to use Spring MVC in this case?