Spring boot 프로젝트 생성

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

VSCODE setting

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

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

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

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

Refer

https://hye0-log.tistory.com/28

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 사용을 위해 추가한 라이브러리들

application.yml

  • JSP 사용을 위한 파일 구조 webapp > WEB-INF > view

스크린샷 2022-09-02 오후 11.19.52.png

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

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

스크린샷 2022-09-02 오후 11.07.38.png

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

localhost:8080/hello.html 을 호출하면 정상적으로 로드된다

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

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

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

Tiles

TilesConfig.java

  • tiles 위치

스크린샷 2022-09-02 오후 11.28.34.png

tiles.xml

layout.jsp

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

Controller

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

Last updated