0

In Spring, relationship between Application Context and Servlet Context is like parent-child. Application Context is the parent here. So, beans of Servlet Context know beans of Application Context, but vise versa is not true. But if I need to do that, is there any way ?

For simplicity, if I inject an Controller into an Service class, what I need to do ? Is there any Application Context refreshing mechanism, after Servlet Context is initialized ?

biqarboy
  • 852
  • 6
  • 15
  • The Application Context and Servlet Context are totally 2 differenct conceptions, there is nothing comparable. it make sence if you mean WebApplicationContext and ApplicationContext is like parent-child. – Laurence Geng Aug 27 '14 at 06:11
  • 1
    You shouldn't injecte a controller in a service. That would ruin your layered architecture where each layer depends on the next one, and not vice-versa. If A must be injected into B, then B should be in the same context as A, or in a sub-context of A. – JB Nizet Aug 27 '14 at 06:21
  • @JBNizet - I want to keep them in different context. Normally we don't inject a controller into a service class. I just need to know if there is any possible way to do that. – biqarboy Aug 27 '14 at 09:54

0 Answers0