codememo

Spring boot MVC: JSP를 찾을 수 없습니다.

tipmemo 2023. 7. 22. 10:06
반응형

Spring boot MVC: JSP를 찾을 수 없습니다.

문제:아래에서 내 견해에 도달할 수 없습니다.WEB-INF/jspSpring Boot 웹 MVC 앱에서.

내가 한 일:

이건 내 JSP야.

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    <ul>
        <%--@elvariable id="users" type="java.util.List"--%>
        <c:forEach items="${utenti}" var="utente">
            <li>
                <c:out value="${utente.getUsername()}"/>
            </li>
        </c:forEach>
    </ul>
</body>
</html>

이것은 내 컨트롤러:

@Controller
public class UtenteController {

    @Autowired
    private UtenteService utenteService;

    @RequestMapping("/lista_utenti")
    public ModelAndView getListaUtentiView(){
        ModelMap model = new ModelMap();
        model.addAttribute("utenti", this.utenteService.getListaUtenti());
        return new ModelAndView("lista_utenti", model);
    }

}

이것은 내 애플리케이션입니다.속성:

# MVC
spring.view.prefix=/WEB-INF/jsp/
spring.view.suffix=.jsp

#Postgres config
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/DB_Test
spring.datasource.username=postgres
spring.datasource.password=postgres

그리고, 적어도, 나의 주요 애플리케이션은:

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class SpringWebApplication extends SpringBootServletInitializer{

    public static void main(String[] args) {
        SpringApplication.run(SpringWebApplication.class, args);
    }

    @Override
    protected final SpringApplicationBuilder configure(final SpringApplicationBuilder application) {
        return application.sources(SpringWebApplication.class);
    }
}

에 가면 얻을 수 있는 것http://localhost:8080/lista_utenti다음과 같습니다.

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Jan 15 15:59:57 CET 2015
There was an unexpected error (type=Not Found, status=404).
No message available

내가 뭘 잘못하고 있는 거지?

지오, 이 의존성을 폼에 포함시킨 게 확실해요?

<dependency>
   <groupId>org.apache.tomcat.embed</groupId>
   <artifactId>tomcat-embed-jasper</artifactId>
   <scope>provided</scope>
</dependency>

이것이 없으면, 나는 당신과 같은 오류를 얻을 것입니다.

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>required</scope>
</dependency>

Intellj에 있는 제 프로젝트에 이것을 추가했고 작동합니다.

나는 이것을 나의 메이븐 의존성에 추가하고 있고 이제 그것은 작동합니다.

<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-tomcat</artifactId>
 <scope>provided</scope>
</dependency>

pom.xml 파일에 Tomcat Embed Jasper 종속성 추가

<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <version>9.0.30</version>
</dependency>

표준 타임리프 프로젝트를 사용하던 것에서 부트스트랩(나처럼)으로 이동했다면 이 종속성을 제거해야 합니다.

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

언급URL : https://stackoverflow.com/questions/27966602/spring-boot-mvc-cant-find-jsp

반응형