티스토리 뷰

이전까지 기본 프로젝트를 생성하였다면 이번에는 간단한 설정을 추가하고 실행을 해보도록 하겠습니다. 

상세 설명은 없습니다. 지금은 그냥 실행만 해보는 겁니다. 

 

1. 기본 설정 추가 

  • application.properties 
  • SpringMVC 설정  

2. 테스트 파일 생성 

3. 실행 및 테스트 

 

1-1. application.properties 내용 추가 

#web server
server.port=8081
server.contextPath=/

# graceful shutdown 
server.shutdown=graceful

#SESSION
server.session.timeout=1800

#file updoad
#spring.http.multipart.enabled=true
#spring.http.multipart.max-file-size=10MB
#spring.http.multipart.max-request-size=10MB
spring.servlet.multipart.enabled=true
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB

## thymeleaf
spring.thymeleaf.prefix=classpath:templates/
spring.thymeleaf.check-template-location=true
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML
spring.thymeleaf.cache=false
spring.thymeleaf.order=1

# INTERNATIONALIZATION (MessageSourceAutoConfiguration)
# Comma-separated list of basenames, each following the ResourceBundle convention.
spring.messages.basename=i18n/messages
# Loaded resource bundle files cache expiration, in seconds. When set to -1, bundles are cached forever.
#spring.messages.cache-seconds=-1
# Message bundles encoding.
spring.messages.encoding=UTF-8
# Set whether to fall back to the system Locale if no files for a specific Locale have been found.
spring.messages.fallback-to-system-locale=true

#LOG 관련 설정 
logging.level.root=INFO
logging.level.org.springframework=INFO
logging.level.eblo.study.springboot=DEBUG
#output to a temp_folder/file
logging.file=${java.io.tmpdir}/study-springboot.log
# Logging pattern for the console
logging.pattern.console= [%d{yyyy-MM-dd HH:mm:ss}] %-5level %logger{36} - %msg%n
# Logging pattern for file
logging.pattern.file= %d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%

1-2. SpringMVC 설정 

package eblo.study.springboot.web.servlet.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class WebMvcConfiguration extends WebMvcConfigurationSupport {

    private static final String CLASSPATH_RESOURCE_LOCATIONS = "classpath:/static";

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/css/**").addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS+"/css/").setCachePeriod(3600);
        registry.addResourceHandler("/images/**").addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS+"/images/").setCachePeriod(3600);
        registry.addResourceHandler("/js/**").addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS+"/js/").setCachePeriod(3600);
        registry.addResourceHandler("/html/**").addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS+"/html/").setCachePeriod(3600);
        registry.addResourceHandler("/favicon.ico"  ).addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS+"favicon.ico"   ).setCachePeriod(3600);
    }
    
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/whoami").setViewName("whoami");
    }

}

2-1. thymeleaf 추가 

/src/main/resources/templates/whoami.html

<!DOCTYPE html>
<html lang="ko">
<head>
    <title>whoami page</title>
    <meta content="text/html; charset=utf-8" />
</head>  
<body>
whoami~~~
</body>
</html>

2-2. html 추가 

/src/main/resources/static/html/hello.html

<!DOCTYPE html>
<html lang="ko">
<head>
    <title>test page</title>
    <meta content="text/html; charset=utf-8" />
</head>  
<body>
hello world ~~~ 
</body>
</html>

 

3-1. 실행

Run Configurations > Spring Boot App > 추가 및 실행(run)

3-2. 확인 

 

'study > springboot' 카테고리의 다른 글

009. controller pathvariable 처리  (0) 2022.05.12
008. Controller request mapping  (0) 2022.05.11
006. 사용자 배너 추가  (0) 2022.05.11
005. Spring annotaion  (0) 2022.05.11
004. 롬복(lombok)  (0) 2022.05.11
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함