• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Do I need to use Spring MVC in this case?

 
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Solved. Yes, needed MVC.
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic