가자공부하러!

9. Spring Boot(2.1.6) Maven 프로젝트 welcome! 보기 + tiles 적용 본문

공부/Spring Boot

9. Spring Boot(2.1.6) Maven 프로젝트 welcome! 보기 + tiles 적용

오피스엑소더스 2019. 8. 29. 17:32



1. 기초 설정

  > spring boot version 2.1.7(Spring Starter Project)

  > jdk 8

  > sts3

  > maven


2. dependencies

  > 프로젝트 생성 시 추가

- Spring Boot DevTools

- Lombok

- MySQL Driver

- MyBatis Framework

- Spring Web Starter

  > 별도 추가

- JSP 수행을 위한 내장 톰캣 : tomcat-embed-jasper

- JSTL

- DB 관련 : spring-boot-starter-jdbc, ojdbc6(pom.xml에 repository등록 필요), h2, HikariCP

- File IO : commons-io, cos, commons-fileupload


3. application.yml

  > view resolver, custom error page, db config(connection pool) 설정


4. view 경로 및 인덱스 페이지 생성

  > src/main/webapp/WEB-INF/views/welcome.jsp


5. MyBatis, Hikari connection pool 설정

  > src에 새 config 패키지 생성, OracleDBConfiguration.java 작성

- HikariConfig -> DataSource -> SqlSessionFactory -> SqlSessionTemplate

  > SqlSessionFactory에 명시한 mapper경로에 xml파일 작성

- src/main/resources/mapper/**/*.xml


6. 컨트롤러 작성


7. 소스코드 : https://github.com/HyeongJunMin/springboot/tree/master/tilesExam


  > 마리아DB, 타일즈 사용을 위한 디펜던시 모음

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.0</version>
        </dependency>
 
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </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>
 
        <!-- JSP lib -->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- JSTL lib -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
        <!-- Need this to compile JSP, tomcat-embed-jasper version is not working, 
            no idea why -->
        <dependency>
            <groupId>org.eclipse.jdt.core.compiler</groupId>
            <artifactId>ecj</artifactId>
            <version>4.6.1</version>
            <scope>provided</scope>
        </dependency>
 
        <!-- Optional, test for static content, bootstrap CSS -->
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>3.3.7</version>
        </dependency>
 
        <!-- DB관련, boot mybatis랑 mysql-connector만 위에 있음 -->
        <!-- H2 for oracle db connection -->
        <!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
        </dependency>
        <!-- maria db 관련 디펜던시 -->
        <dependency>
            <groupId>org.mariadb.jdbc</groupId>
            <artifactId>mariadb-java-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
 
        <!-- file io on web -->
        <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.servlets/cos -->
        <dependency>
            <groupId>com.servlets</groupId>
            <artifactId>cos</artifactId>
            <version>09May2002</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.4</version>
        </dependency>
 
        <!-- Tiles 관련 디펜던시 -->
        <!-- https://mvnrepository.com/artifact/org.apache.tiles/tiles-api -->
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-api</artifactId>
            <version>3.0.7</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.tiles/tiles-core -->
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-core</artifactId>
            <version>3.0.7</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.tiles/tiles-servlet -->
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-servlet</artifactId>
            <version>3.0.7</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.tiles/tiles-template -->
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-template</artifactId>
            <version>3.0.7</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.tiles/tiles-jsp -->
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-jsp</artifactId>
            <version>3.0.7</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-autotag-core-runtime</artifactId>
            <version>1.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-request-api</artifactId>
            <version>1.0.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-request-jsp</artifactId>
            <version>1.0.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-request-servlet</artifactId>
            <version>1.0.6</version>
        </dependency>
        <!-- Tiles 관련 디펜던시 끝 -->
</dependencies>
cs



참고 블로그 : jmlim.github.io/spring/2019/02/08/spring-boot-tiles/index



Comments