3

I'm trying to move from xml config to java config. The application can start without any errors, however the jsp returned with the $END$ when content is different.

I believe I made some stupid mistake somewhere and there are no exceptions thrown

Note: when using xml config everything is working fine

Configuration Class

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;

@Configuration
@EnableWebMvc
@ComponentScan("app.test.portal")
public class PortalConfiguration {

    @Bean
    public ViewResolver viewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setViewClass(JstlView.class);
        viewResolver.setPrefix("/WEB-INF/views/");
        viewResolver.setSuffix(".jsp");

        return viewResolver;
    }
}

Initializer Class

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

public class PortalInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{PortalConfiguration.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return null;
    }

    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }
}

Controller

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class IndexController {

    @RequestMapping(value = "/home", method = RequestMethod.GET)
    public String index() {
        return "index";
    }
}
Duy Anh
  • 750
  • 1
  • 7
  • 24
  • Might be this post will help you out :- http://stackoverflow.com/questions/24014919/converting-spring-xml-file-to-spring-configuration-class – SaviNuclear Sep 08 '16 at 11:58
  • @Henry, the question was asked 2 months ago, and I thought i might share a solution. Now that you mentioned, i'll move it to answers – Duy Anh Nov 22 '16 at 06:57

1 Answers1

1

Configurations was pointing at a non existing WebApp folder

Duy Anh
  • 750
  • 1
  • 7
  • 24