🐳
Engineering Wiki
  • 🖐️Welcome
  • 📚백엔드 로드맵
    • 메인페이지
  • Spring
    • spring boot
      • security
        • security 기본
        • filter
        • JWT
      • 스프링 핵심 원리
        • 객체지향 설계와 스프링
        • 스프링IoC컨테이너와 bean
      • IntelliJ
        • Spring boot 생성 및 git clone
        • Spring boot 프로젝트 생성
      • vscode
        • Spring boot 프로젝트 생성
      • scheduling
        • 스케쥴링 설정시 에러 상황
      • paging
      • 에러 핸들링
        • ErrorCode생성 및 ExceptionHandler로 에러처리
        • Security & JWT 에러처리
        • spring cloud sleuth
      • 로그 핸들링
        • logback
        • HttpRequestServlet 래핑
      • gradle
        • hidetake.ssh 키파일 설정
      • maven
        • maven tomcat
      • lib
        • lombok
        • tiles
      • API 부하테스트 툴 K6
      • JPA
        • Mybatis / JPA 차이
      • Mybatis
    • spring batch
      • batch
        • Spring Batch 기본개념
  • FRONT
    • vue
      • Spring boot & Vue.js 설치 및 연동
      • Spring boot & Vue.js 웹개발 세팅
      • vue의 기본구조 실행순서
      • SPA 이해
  • JAVA
    • 환경설정
    • 자바의 정석
      • generics
  • DATABASE
    • mongoDB
      • 정규표현식을 사용해 대소문자 구분없이 검색
      • mongoDB export import
      • MAC 설치 및 실행
    • MYSQL
      • dbeaver 데이터 내보내기 불러오기
      • [에러] 스프링 mysql 8 연결 에러
      • MAC M1 mysql 설치
      • GROUP BY 정리
      • 테이블 명세서 빠르게 생성
  • AWS
    • IAM
    • 설치&명령어
      • eb 설치 & 명령어
      • CLI 설치 & 명령어
    • sam
      • SAM 개념
      • SAM Lambda S3이벤트 트리거, MongoDB 접근코드
      • SAM intellij 배포
    • peering
      • mongodb atlas AWS vpc peering
      • MongoDB & Lambda VPC peering ,endpoint설정
    • 쉘스크립트
      • 도커 컨테이너 중단시 슬랙 리포팅 및 재실행
  • DOCKER
    • 설치&명령어
      • Docker 기초
      • Docker Container 유용한 명령어
    • MAC관련 문제
      • 이미지 빌드 관련 문제상황
      • MAC M1 도커 실행 원리
      • [에러] docker: Error response from daemon: Mounts denied:
  • ELK
    • 세팅
      • 로드벨런서에 logstash 세팅
      • Elastic Beanstalk + Elastic Cloud + docker 설정
      • ElasticCloud + filebeat + logstash + docker 설정 (버전8.5.0)
      • ELK 적용 사례, 로그수집(filebeat/logstash) 설명
    • logstash
      • Logstash는 로그를 왜 message라는 field로 저장할까?
      • logstash health check
    • filebeat
      • filebeat 아키텍쳐
  • unity
    • 유니티 기본
      • 캐릭터 이동
      • 카메라
  • WORDPRESS
    • 워드프레스 기본
  • git
    • GIT 개념
      • 라이프사이클
    • 명령어
      • defult 브랜치 main 으로 변경
      • 첫번째 커밋 삭제(브런치삭제) 후 원격저장소에 강제 push
      • git 원격저장소에 remote 방법(vscode로 진행)
      • git gh
      • git reset
      • git rebase
  • MAC
    • 개발 환경세팅
      • 맥 초기 개발세팅
    • 유용한내용
      • app store 다운로드 없이 웹에서 Xcode 다운
      • ubuntu iso 설치 usb 만들기
      • 응용프로그램 에러
      • 잠김 파일
  • CS
    • data structure & algorism
      • 자료구조의 정의 및 종류
  • 방통대
    • 대학수학의 이해
      • 1강. 수학의 기초(1)
    • 딥러닝
      • 1강.신경망의 개요
  • NODE
    • 개발기록
      • 인스타그램 API 활용하여 게시물 슬랙에 리포팅
Powered by GitBook
On this page
  • VSCODE setting
  • build.gradle
  • application.yml
  • Tiles
  1. Spring
  2. spring boot
  3. vscode

Spring boot 프로젝트 생성

PreviousvscodeNextscheduling

Last updated 2 years ago

생성일: 2022년 9월 2일 오후 10:19

VSCODE setting

  • 스프링부트는 JSP 를 권장하지 않음

  • JSP를 사용하게 되면 WAR로 패키징 해야함, Tiles같은 라이브러리가 WAR에서만 정상작동 (직접확인함)

  • 또한 JAR로 패키징할때 JSP로딩에 문제가 있고 제약이 있다고함

  • 본인은 jsp라이브러리를 설치후 jar로 실행했을때 로딩은 잘 되었었으나 tiles 때문에 war로 패키징함

Refer

build.gradle

plugins {
	id 'org.springframework.boot' version '2.7.3'
	id 'io.spring.dependency-management' version '1.0.13.RELEASE'
	id 'java'
	id 'war'
}

group = 'com.rootenergy'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '8'

configurations {
	compileOnly {
		extendsFrom annotationProcessor
	}
}

repositories {
	mavenCentral()
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-web'
	implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.2.0'
	implementation 'com.google.code.gson:gson:2.8.0'
	implementation 'org.apache.httpcomponents:httpclient:4.3.6'
	implementation 'com.sun.mail:javax.mail:1.6.1'
	compileOnly 'org.projectlombok:lombok'
	developmentOnly 'org.springframework.boot:spring-boot-devtools'
	runtimeOnly 'mysql:mysql-connector-java:8.0.28'
	annotationProcessor 'org.projectlombok:lombok'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testImplementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter-test:2.2.2'
	implementation 'org.apache.poi:poi:3.7'
	implementation 'org.apache.poi:poi-ooxml:3.7'
	implementation 'javax.servlet:jstl'
  implementation "org.apache.tomcat.embed:tomcat-embed-jasper"
	implementation group: 'org.apache.tiles', name: 'tiles-jsp', version: '3.0.5'

}

tasks.named('test') {
	useJUnitPlatform()
}

war {
	archiveName('erp.war')
}
  • jsp 사용을 위해 추가한 라이브러리들

//jsp
implementation 'javax.servlet:jstl'
implementation "org.apache.tomcat.embed:tomcat-embed-jasper"
//tiles
implementation group: 'org.apache.tiles', name: 'tiles-jsp', version: '3.0.5'

application.yml

spring:
  mvc:
    static-path-pattern: /resources/**
    view:
      prefix: /WEB-INF/view/
      suffix: .jsp
  datasource:
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: /*url*/
        username: /*username*/
        password: /*password*/

mybatis: 
    typeAliasesPackage: com.rootenergy.erp.entity
    mapper-locations: classpath:mapper/**/*.xml
  • JSP 사용을 위한 파일 구조 webapp > WEB-INF > view

스프링부트에는 정적자원 접근을 위한 디폴트 설정이 있다

보면 스프링부트는 resources > static 에서 정적자원에 접근한다 (자동생성된폴더)

public class ResourceProperties {
    private static final String[] CLASSPATH_RESOURCE_LOCATIONS = new String[]{"classpath:/META-INF/resources/", 
    "classpath:/resources/", "classpath:/static/", "classpath:/public/"};
출처: https://warpgate3.tistory.com/164 [무명소졸의 웹개발:티스토리]

static 파일 아래 hello.html 파일을 두고

  • 별도의 설정을 통해 원하는 URI패턴을 정해줄수도 있다

    • static-path-pattern: /resources/** → /resources/hello.html 로 호출

  • prefix , suffix 설정 (ModelAndView객체에서 선언된 View Page를 지정해주는 클래스의 프로퍼티임)

spring:
  mvc:
    static-path-pattern: /resources/** => 정적파일
    view:
      prefix: /WEB-INF/view/
      suffix: .jsp

Tiles

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.view.tiles3.TilesConfigurer;
import org.springframework.web.servlet.view.tiles3.TilesView;
import org.springframework.web.servlet.view.tiles3.TilesViewResolver;

@Configuration
public class TilesConfig {

    @Bean
	public TilesConfigurer tilesConfigurer() {
        final TilesConfigurer configurer = new TilesConfigurer();
        //해당 경로에 tiles.xml 파일을 넣음
        configurer.setDefinitions(new String[]{"/WEB-INF/tiles/tiles.xml"});
        configurer.setCheckRefresh(true);
        return configurer;
    }

    @Bean
    public TilesViewResolver tilesViewResolver() {
        final TilesViewResolver tilesViewResolver = new TilesViewResolver();
        tilesViewResolver.setViewClass(TilesView.class);
        return tilesViewResolver;
    }
    
}
  • tiles 위치

tiles.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
       "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
   <!-- 기본 레이아웃 -->
    <definition name="layout" template="/WEB-INF/tiles/components/layout.jsp">
        <put-attribute name="header" value="/WEB-INF/tiles/components/header.jsp" />
        <put-attribute name="content" value="" />
        <put-attribute name="footer" value="/WEB-INF/tiles/components/footer.jsp" />
    </definition>
    
    <definition name="layout/*/*" extends="layout">
        <put-attribute name="content" value="/WEB-INF/view/{1}/{2}.jsp" />
    </definition>

    <!-- 레이아웃 없음 -->
    <definition name="loginlayout" template="/WEB-INF/tiles/components/loginlayout.jsp">
        <put-attribute name="header" value="" />
        <put-attribute name="content" value="" />
        <put-attribute name="footer" value="" />
    </definition>
    
    <definition name="loginlayout/*/*" extends="loginlayout">
        <put-attribute name="content" value="/WEB-INF/view/{1}/{2}.jsp" />
    </definition>

</tiles-definitions>

layout.jsp

  • tiles.xml 에서 명시한 위치의 header, content, footer를 해댱위치에 넣어줌

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
		<!-- Main wrapper  -->
    <tiles:insertAttribute name="header" />
    <tiles:insertAttribute name="content" />
    <tiles:insertAttribute name="footer" />
</body>
</html>

Controller

  • tiles.xml 에서 설정한 대로 layout// → layout/main/index 이런식으로 URI를 호출해야함

/**
     * 로그인,메인 페이지 이동
     */
    @RequestMapping(value="/", method=RequestMethod.GET)
    public ModelAndView main(Model model, HttpSession session) {
        String returnUrl = "";

        Member member = (Member) session.getAttribute("MEMBER");

        if(member != null && !Util.chkNull(member.getId())){
            returnUrl = "layout/main/index";
        }
        else{
            returnUrl = "loginlayout/main/login";
        }

        return new ModelAndView(returnUrl);
    }

을 호출하면 정상적으로 로드된다

https://hye0-log.tistory.com/28
localhost:8080/hello.html
TilesConfig.java
스크린샷 2022-09-02 오후 11.19.52.png
스크린샷 2022-09-02 오후 11.07.38.png
스크린샷 2022-09-02 오후 11.28.34.png