Hejka
Mam sobie taki oto projekt:
Łapię 404 - a to niespodzianka. Wygląda tak jakby Spring nie korzystał z resolvera, który zdefiniowałem w klasie Main
:
@EnableWebMvc
@Configuration
@ComponentScan("com.burdzi0.mvc")
public class Main {
@Bean
public InternalResourceViewResolver getInternalResourceViewResolver() {
String prefix = "/WEB-INF/jsp/", suffix = ".jsp";
return new InternalResourceViewResolver(prefix, suffix);
}
}
Mam kontroller:
@Configuration
public class DefaultController {
@RequestMapping("/")
public String index(Model model) {
model.addAttribute("title", "TITLE");
model.addAttribute("body", "BODY");
return "hello";
}
}
do pliku jsp
:
<%--
Created by IntelliJ IDEA.
User: burdzi0
Date: 18.03.18
Time: 22:35
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>${title}</title>
</head>
<body>
<p>${body}</p>
</body>
</html>
oraz mój config:
@Configuration
public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
@Nullable
protected Class<?>[] getRootConfigClasses() {
return new Class[]{WebConfig.class};
}
@Nullable
protected Class<?>[] getServletConfigClasses() {
return new Class[]{WebConfig.class};
}
}
Czy korzystam z dobrych klas/interfejsów do Java Configu? Gdzie może leżeć błąd?
Robiłem według tego tutoriala: https://howtodoinjava.com/spring5/webmvc/spring5-mvc-hibernate5-example/
- screenshot-20180318231103.png (30 KB) - ściągnięć: 82