I've got 404, then rebuilt project. Now it's working, but my mind don't (Java, Spring MVC, Tomcat 10)

53 views Asked by At

I'm writing a simple messenger (or trying at least) on Java 21, Spring 6.0.13, Tomcat 10.1.16. Getting 404 error on deploy every time and have zero ideas what's wrong.

UPD: Well, for some reason, completely same project written from zero works absolutely fine, guess something went wrong after i deleted it and got back from git hub repo. It is working now, but i still got question - what was that? And how to fix this without making same programm again? It is a small project for learning, so not a big deal, but imagine doing this on actual app? Need an answer, thanks in advance.

Git Hub repository - https://github.com/anxidy/Messenger

My pom.xml

<properties>
    <spring.version>6.0.13</spring.version>

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>21</maven.compiler.source>
    <maven.compiler.target>21</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.13.2</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.hibernate.orm</groupId>
      <artifactId>hibernate-core</artifactId>
      <version>6.3.0.FINAL</version>
    </dependency>

    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
      <version>2.2.224</version>
    </dependency>

    <dependency>
      <groupId>jakarta.persistence</groupId>
      <artifactId>jakarta.persistence-api</artifactId>
      <version>3.1.0</version>
    </dependency>

    <dependency>
      <groupId>jakarta.servlet</groupId>
      <artifactId>jakarta.servlet-api</artifactId>
      <version>6.0.0</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>jakarta.servlet.jsp</groupId>
      <artifactId>jakarta.servlet.jsp-api</artifactId>
      <version>3.1.1</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>jakarta.websocket</groupId>
      <artifactId>jakarta.websocket-api</artifactId>
      <version>2.1.0</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>jakarta.el</groupId>
      <artifactId>jakarta.el-api</artifactId>
      <version>5.0.1</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>jakarta.security.enterprise</groupId>
      <artifactId>jakarta.security.enterprise-api</artifactId>
      <version>3.0.0</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>jakarta.annotation</groupId>
      <artifactId>jakarta.annotation-api</artifactId>
      <version>2.1.1</version>
    </dependency>

    <dependency>
      <groupId>org.glassfish.web</groupId>
      <artifactId>jakarta.servlet.jsp.jstl</artifactId>
      <version>3.0.1</version>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>${spring.version}</version>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-orm</artifactId>
      <version>${spring.version}</version>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>${spring.version}</version>
    </dependency>
  </dependencies>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns = "https://jakarta.ee/xml/ns/jakartaee"
         xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation = "https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
         version = "6.0">

    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>

    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <init-param>
            <param-name>contextClass</param-name>
            <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
        </init-param>

        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>ru.anxidy.web.AppConfig</param-value>
        </init-param>

        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

Controller

@Controller
public class MainPageController {
    @GetMapping(path = "/")
    public String index() {
        return "mainPage";
    }
}

and Config

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.jsp("/pages/",".jsp").viewClass(JstlView.class);
    }
}

"mainPage" is a jsp in pages folder.

Deploying this on Tomcat returns a 404 page, no logs, no other errors, nothing. I don't understand what i'm missing. I've reinstalled Tomcat several times, re-made artifact and facet too. Please, help me out.

0

There are 0 answers