Framework Error
Cannot instantiate interface: org.springframework.web.servlet.view.JstlView
What This Error Means
This error occurs when attempting to instantiate a non-abstract class that is an interface, which is not allowed in Java. In the context of Spring MVC, this typically happens when a view resolver is misconfigured.
Why It Happens
This is because Spring attempts to resolve a view using the provided view name, but the corresponding view class is an interface. This can occur when a developer mistakenly returns an interface instead of a concrete implementation from a view resolver.
How to Fix It
- 1To fix this error, identify the view resolver that is causing the issue and replace it with a concrete view class. Alternatively, ensure that the view resolver is properly configured to return an instance of the view class. For example, if using a BeanNameViewResolver, configure it to return a concrete BeanViewResolver instead. Update your configuration to include the following code:
- 2@Bean
- 3public ViewResolver viewResolver() {
- 4 return new BeanNameViewResolver();
- 5}
Example Code Solution
@Bean
public ViewResolver viewResolver() {
return new BeanNameViewResolver();
}@Bean
public ViewResolver viewResolver() {
return new InternalResourceViewResolver();
}Fix for Cannot instantiate interface: org.springframework.web.servlet.view.JstlView
Browse Related Clusters
Related JAVA Errors
java.lang.StackOverflowError at com.example.Main.main(Main.java:15) -
Error executing SQL query: Cannot insert explicit value for identity c
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
Cannot find symbol: variable 'name' in void main(String[] args)
Related JAVA Blog Articles
Have a different error? Get an instant explanation.
Explain Another Error