Spring JSON View: ApplicationObjectSupport does not start on ApplicationContext
I am trying to use 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 am getting the following error:
java.lang.IllegalStateException: ApplicationObjectSupport instance [org.springframework.web.servlet.view.json.JsonView] does not start in ApplicationContext
The weird thing is that when I implement the Controller interface directly and don't inherit, everything is fine. The error only occurs when I inherit from AbstractController
.
In my current case, although I would like to extend AbstractFormController
and therefore cannot write a class that does not inherit from AbstractController
.
Any ideas?
source to share
This is a rather misleading error message, in fact it is complaining that the JsonView is not working in the context of the application. This means the JsonView
bean was not created by Spring, but you created it yourself ( JsonView
extends ApplicationObjectSupport
and therefore must be Spring-managed).
However, you have not provided us with any of your codes, so it's hard to say for sure. I'm assuming your controller creates it by itself JsonView
? You should let Spring do this, either by injecting a JsonView
bean into the controller, or perhaps using ViewResolver
(if Spring-Json supplies one).
source to share
If you are doing Java configuration (as opposed to XML), in your configuration class, you can call a method setApplicationContext
on the object that is complaining.
Here's what helped in Spring MVC 3.2.2 when trying to initialize ContentNegotiatingViewResolver
in Java.
Here's an example of a config class:
@Configuration
@EnableWebMvc
...
public class MyConfig
{
@Inject
private ApplicationContext appContext;
@Bean
public ContentNegotiatingViewResolver contentNegotiatingViewResolver ( )
{
ContentNegotiatingViewResolver retVal =
new ContentNegotiatingViewResolver( );
...
retVal.setApplicationContext( appContext );
return retVal;
}
}
source to share