setting up spring view resolver using spring-java-config

admin

Administrator
Staff member
I am trying to setup view-resolver for spring using java-config. I have tried 3 different method with different config found in 3 different sites. All of them working fine. My question is that <strong>Is there any specific standard / method / signature / interface method to defining the view-resolver ?</strong>

Code:
@Bean 
public InternalResourceViewResolver setupViewResolver()  {
    InternalResourceViewResolver resolver =  new InternalResourceViewResolver ();
    resolver.setPrefix ("/WEB-INF/pages/");
    resolver.setSuffix (".jsp");
    resolver.setViewClass (JstlView.class);
    return resolver;
}

ref-link <a href="http://habrahabr.ru/post/226663/" rel="nofollow">http://habrahabr.ru/post/226663/</a>

Code:
@Bean
public InternalResourceViewResolver jspViewResolver() {
    InternalResourceViewResolver bean = new InternalResourceViewResolver();
    bean.setPrefix("/WEB-INF/pages/");
    bean.setSuffix(".jsp");
    return bean;
}

ref-link <a href="https://samerabdelkafi.wordpress.com/2014/08/03/spring-mvc-full-java-based-config/" rel="nofollow">https://samerabdelkafi.wordpress.com/2014/08/03/spring-mvc-full-java-based-config/</a>

Code:
@Bean
public ViewResolver contentNegotiatingViewResolver(ContentNegotiationManager manager) {
        List&lt; ViewResolver &gt; resolvers = new ArrayList&lt; ViewResolver &gt;();

        InternalResourceViewResolver r1 = new InternalResourceViewResolver();
        r1.setPrefix("/WEB-INF/pages/");
        r1.setSuffix(".jsp");
        r1.setViewClass(JstlView.class);
        resolvers.add(r1);

        JsonViewResolver r2 = new JsonViewResolver();
        resolvers.add(r2);

        ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver();
        resolver.setViewResolvers(resolvers);
        resolver.setContentNegotiationManager(manager);
        return resolver;
}

ref-link <a href="http://fruzenshtein.com/spring-java-configurations/" rel="nofollow">http://fruzenshtein.com/spring-java-configurations/</a>