I configured the Application and code the "DispatcherServlet" to viewResolver like this:
@Configuration
@EnableWebMvc
@ComponentScan ({"controllers"})
@EnableAutoConfiguration
@SpringBootApplication
public class Application {
@Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
public static void main(String[] args){
SpringApplication.run(Application.class, args);
}
}
Controller class to handle requests looks this:
@Controller
public class HelloControllerImpl {
@RequestMapping(value= "/welcome", method= RequestMethod.GET)
public String getWelcomePage(ModelMap model) {
model.addAttribute("message", "Spring 3 MVC - Hello World");
model.addAttribute("name", "vzateychuk");
return "welcome";
}
}
The view file: \WEB-INF\views\welcome.jsp
<html>
<body>
<h1>Hello, : ${name}</h1>
<h2>Message : ${message}</h2>
</body>
</html>
The application structure: Welcome application structure
I think that something is missing in the configuration files, but I can not see. Could you guest what is wrong and what means: "No mapping found for HTTP request with URI [/WEB-INF/views/welcome.jsp]"? Should I provide xml configuratin like dispatcher-servlet.xml or something like that? Thank you in advance.
Update: I guessing that my DispatcherServlet unable to find the appropriate view. I have tryed to completely delete /WEB-INF directory, but nothing changes. Probably something wrong with this code:
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
**viewResolver.setPrefix("/WEB-INF/views/");**
.... Can anybody guess what can be wrong? (May it be if the anotation @EnableAutoConfiguration not allow to define viewResolver's prefix?
I did simple project similiar to yours. You can check on my github
What you have to do is:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<scope>provided</scope>
</dependency>
For that point you will find the explanation here mvn spring-boot:run
You may also configure your IDEA to run that command. Go to Run->Edit Configuration, click green plus sign on the left side and choose Maven. Then in the "Command line" field write "spring-boot:run", press ok.
And run this configuration.Note that you need @ComponentScan ({"controllers"}), because of your package structure - you have Application class in different package than your controller.