[IntelliJ/HTML/Spring Boot] cannot resolve mvc view 'index.html'
본문 바로가기

Web 개발/Java, SpringBoot, JPA

[IntelliJ/HTML/Spring Boot] cannot resolve mvc view 'index.html'

728x90
반응형

프로젝트를 생성 시, Spring Web, JPA 을 추가했더니

configuration을 추가하지 않아도 해결되었다.

 

따라서 프로젝트를 새로 생성하거나,

다음과 같이 poem.xml 과 application.yml을 수정할 것을 권장

 

// poem.xml

<dependencies>
		<!-- JPA 하이버네이트 -->
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-entitymanager</artifactId>
			<version>5.3.10.Final</version>
		</dependency>
        
		<!-- Spring Boot -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

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

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

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-configuration-processor</artifactId>
			<optional>true</optional>
		</dependency>

</dependencies>

 

//application.yml

spring:
  jpa:
    hibernate:
      ddl-auto: create
    show-sql: true
    properties:
      hibernate.format_sql: true

 

 

 

 

 

============================================================================

 

프로젝트를 새로 시작하면서 IntelliJ로 툴을 바꾸게 되었다.

 

Controller에서 화면을 찾지 못해서 한참 헤맸는데

알고보니 html이 static이 아닌 template에 있어서 발생하는 오류였다.

 

다음과 같이 해결해주었다.

 

1. BoardConfiguration 클래스 추가

 

2. Configuration에 다음과 같이 작성

package com.example.board.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.CacheControl;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.concurrent.TimeUnit;

@Configuration
public class BoardConfiguration implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(final ResourceHandlerRegistry registry){
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/templates/")
                .setCacheControl(CacheControl.maxAge(10, TimeUnit.MINUTES));
    }
}

 

출처: bottom-to-top.tistory.com/38

728x90
반응형