I’m trying to use a Json View for Spring (http://spring-json.sourceforge.net/) (org.springframework.web.servlet.view.json.JsonView) but whenever I write a controller class that extends AbstractController I get the following Error:
java.lang.IllegalStateException: ApplicationObjectSupport instance [org.springframework.web.servlet.view.json.JsonView] does not run in an ApplicationContext
The weird thing is, that when I implement the Controller interface directly and do not inherit, it is fine. The error only happens when I inherit from AbstractController.
In my current case though I would like to extend AbstractFormController and hence can’t write a class that does not inherit from AbstractController.
Any ideas?
That’s a rather misleading error message, it’s actually complaining that the JsonView is not running inside an app context. What it means is that the
JsonViewbean was not instantiated by Spring, but that you instantiated it yourself (JsonViewextendsApplicationObjectSupport, and should therefore be Spring-managed).However, you haven’t given us any of your code, so it’s hard to tell for sure. I’m guessing your controller is instantiating
JsonViewitself? You need to let Spring do that, either by injecting aJsonViewbean into the controller, or perhaps using aViewResolver(if Spring-Json supplies one).