У меня проблемы с настройкой проекта Spring MVC в IntelliJ (я не могу использовать Spring Boot в этом проекте).
Кажется, я не могу ударить мой контроллер:
package app.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletRequest;
@Controller
@RequestMapping(value = "/user")
public class UserController {
@RequestMapping(value = "/registerUser", method = RequestMethod.GET)
public String registerUser(Model m, HttpServletRequest request) {
System.out.println("HERE");
return "index";
}
}
, как явсегда получаю ошибку 404 при попытке использовать localhost: 8080 / user / registerUser.
Я понял, что для того, чтобы иметь класс HttpServletRequest, мне нужно либо импортировать последнюю зависимость в моем файле pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.nemanjagajic</groupId>
<artifactId>Reserve</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.3.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.4.1.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.11.1.RELEASE</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
или я могу зайти в Файл-> Структура проекта-> Модули, выбрать вкладку Зависимости и затем добавить библиотеку Tomcat 9.0.6, но в любом случае я не могу поразить свой контроллер.Похоже, что тот же проект работает в Eclipse, так что я думаю, что это как-то связано с настройкой сервера aka tomcat, но я изо всех сил пытаюсь найти способ правильно настроить его в IntelliJ.
Я оставлю githubхранилище проекта, если кто-то хочет попробовать: https://github.com/nemanjagajic/Reserve