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";
    }
}
2
  • Might be this post will help you out :- stackoverflow.com/questions/24014919/… Commented Sep 8, 2016 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 Commented Nov 22, 2016 at 6:57

1 Answer 1

1

Configurations was pointing at a non existing WebApp folder

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.