Spring JSON View: ApplicationObjectSupport does not run in an ApplicationContext

java, json, spring

Solution

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 `JsonView` bean was not instantiated by Spring, but that you instantiated it yourself (`JsonView` extends `ApplicationObjectSupport`, 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 `JsonView` itself? You need to let Spring do that, either by injecting a `JsonView` bean into the controller, or perhaps using a `ViewResolver` (if Spring-Json supplies one).

Problem

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?

Original source