Antes de mais nada, procurei no forum problemas semelhantes, e vi que meu problema aparentemente não é relacionado aos outro casos de erro 404 outros colegas passaram.
Pessoal, infelizmente, no fim da primeira aula não consegui acessar a página home.jsp, e recebo o erro 404.
Minhas classes
HomeController
package com.livrariasmelo.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HomeController {
@RequestMapping("/")
public String index() {
System.out.println("Acessando a página inicial");
return "home";
}
}
AppWebConfiguration
package com.livrariasmelo.conf;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import com.livrariasmelo.controllers.HomeController;
@EnableWebMvc
@ComponentScan(basePackageClasses = {HomeController.class})
public class AppWebConfiguration {
@Bean
public InternalResourceViewResolver internalResourceViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("WEB-INF/views/");
resolver.setSuffix(".jsp");
return resolver;
}
}
ServletSpringMVC
package com.livrariasmelo.conf;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
public class ServletSpringMVC extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
// TODO Auto-generated method stub
return null;
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[] {AppWebConfiguration.class};
}
@Override
protected String[] getServletMappings() {
return new String[] {"/"};
}
}
home.jsp - a view
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Livraria</title>
</head>
<body>
<h1>Livraria</h1>
</body>
</html>
Obs: não existe nenhum outro arquivo jsp em meu projeto. Obs2: Estou utilizando o Java11 no Ubuntu, isso faz a diferença? Obs3: Já tentei criar o projeto do zero e também importar o arquivo disponibilizado pelo professor, mas os dois casos apresentaram o erro 404. Será algum problema de ambiente em meu PC?