Answer the question
In order to leave comments, you need to log in
How to solve this problem when starting a Spring project??
Hello, I'm doing a project from this site " spring-projects.ru/guides/serving-web-content ", I do everything as it is written, but when I start it, I get the error "[nio-8080-exec-1] oaccC[.[.[/ ].[dispatcherServlet] : Servlet.service() for servlet dispatcherServlet threw exception"
I don't understand what's the problem?
Here is the code:
package hello;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class GreetingController {
@RequestMapping("/greeting")
public String greeting(@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) {
System.out.println("Тут");
model.addAttribute("name", name);
return "greeting.html";
}
}
package hello;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<title>Getting Started: Serving Web Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'Hello, ' + ${name} + '!'" ></p>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
Basically, here is your error:
It looks like you have a /greeting.html route and a template.
Try replacing return "greeting.html";
withreturn "greeting";
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question