250x250
Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- Spring Boot
- AJAX
- maven
- Source
- Python
- error
- SpringBoot
- Open Source
- Eclipse
- JavaScript
- MSSQL
- jpa
- spring
- Core Java
- ubuntu
- STS
- 문서
- oracle
- myBatis
- Tomcat
- git
- Thymeleaf
- IntelliJ
- Docker
- JDBC
- 오픈소스
- PostgreSQL
- 설정
- Exception
- MySQL
Archives
- Today
- Total
헤르메스 LIFE
[SpringBoot] Spring Boot에서 JSP 사용 본문
728x90
개발환경
1. STS 버전 : 4.13.1
2. JDK 버전 : OpenJDK 11.0.14_9_x64
3. Tomcat 버전 : 9.0.56
4. Maven 버전 : 3.8.4
5. Spring 버전 : Spring Boot 2.6.3
Spring Boot 를 설정하면서, Tomcat을 추가해 뒀는데..
Tomcat plugin 은 JSP를 실행할 수 없는 모양입니다.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
Dependency를 추가해야 합니다.
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.3</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.study</groupId>
<artifactId>springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>springboot</name>
<description>Demo project for Spring Boot</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
</properties>
<dependencies>
<!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-oauth2-client</artifactId> </dependency>
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</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-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mustache</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-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Dependency를 추가하고 jar 파일 다운로드 오류로 많은 시간을 허비했습니다.
Maven 의 문제인지, Eclipse의 문제인지.. ㅠ.ㅠ
The container 'Maven Dependencies' references non existing library 'C:\repository\org\apache\tomcat\embed\tomcat-embed-jasper\9.0.56\tomcat-embed-jasper-9.0.56.jar'
https://hermeslog.tistory.com/574
package com.study.springboot.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
// @ComponentScan
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
// @Bean
// public ViewResolver viewResolver() {
// InternalResourceViewResolver viewResolver = new
// InternalResourceViewResolver();
// viewResolver.setPrefix("/WEB-INF/");
// viewResolver.setSuffix(".jsp");
//
// return viewResolver;
// }
/**
* Spring 3.1부터 사용가능
* @EnableWebMvc를 설정하고, WebMvcConfigurer를 상속받아
* viewResolver 함수를 대체한다.
*/
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
registry.jsp("/WEB-INF/jsp/", ".jsp");
}
}
Spring Boot 환경이라 WebConfig.java 를 삭제하고, application.yml 설정으로 처리할 수 있습니다.
spring:
mvc:
view:
prefix: /WEB-INF/jsp/
suffix: .jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello Spring</title>
</head>
<body>
Hello Spring ~~
</body>
</html>
728x90
'Spring Boot Framework' 카테고리의 다른 글
Common Application Properties (0) | 2022.02.27 |
---|---|
[Spring Boot] Multi FileUpload (0) | 2022.02.27 |
[Spring Boot] HikariCP를 이용한 Multi Database Connection + JPA (0) | 2022.02.24 |
[Spring Boot] HikariCP를 이용한 Database Connection + JPA (0) | 2022.02.11 |
[Spring Boot] STS 를 이용한 Spring Boot 개발환경 테스트 (0) | 2022.02.10 |