얕은 지식이지만, 현재 사용중인 라이브러리 등 처음에 해야 하는 환경 설정에 대해 정리한 문서입니다.
이번 포스팅은 자바 스프링 프레임워크 환경 설정에 대해 다루도록 하겠습니다.
먼저 가장 많이 사용 하는 Oracle(오라클)과 Mysql 중 먼저 Mysql 설정 하는 방법을 알려드리도록 하겠습니다.

pom.xml

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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<?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 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>kr.or.infobee</groupId>
    <artifactId>infobee</artifactId>
    <name>SpringMVC(1)</name>
    <packaging>war</packaging>
    <version>1.0.0-BUILD-SNAPSHOT</version>
    <properties>
        <java-version>1.8</java-version>
        <org.springframework-version>4.3.20.RELEASE</org.springframework-version>
        <org.aspectj-version>1.9.1</org.aspectj-version>
        <org.slf4j-version>1.6.6</org.slf4j-version>
<!--         <oracle.ojdbc14.version>11.2.0.2.0</oracle.ojdbc14.version> -->
    </properties>
 
    <repositories>
        <!-- 외부 public 레파지스토리 서버 등록(인터넷이 되는 환경) -->
        <repository>
            <id>central</id>
            <url>http://central.maven.org/maven2/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
 
        <!-- 사설 내부 private 레파지스토리 서버등록 (인터넷이 안되고 사설 서버가 구축 되어 있을 경우) -->
        <repository>
            <id>public</id>
            <url>http://osg.iptime.org/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
 
    <dependencies>
 
<!--         <dependency> -->
<!--             <groupId>oracle</groupId> -->
<!--             <artifactId>ojdbc14</artifactId> -->
<!--             <version>${oracle.ojdbc14.version}</version> -->
<!--         </dependency> -->
 
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework-version}</version>
            <exclusions>
                <!-- Exclude Commons Logging in favor of SLF4j -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
 
        <!-- AspectJ -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${org.aspectj-version}</version>
        </dependency>
 
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>${org.aspectj-version}</version>
        </dependency>
 
 
 
        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${org.slf4j-version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${org.slf4j-version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${org.slf4j-version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.15</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.mail</groupId>
                    <artifactId>mail</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.jms</groupId>
                    <artifactId>jms</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
            </exclusions>
            <scope>runtime</scope>
        </dependency>
 
        <!-- @Inject -->
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>
 
        <!-- Servlet -->
        <!-- <dependency> -->
        <!-- <groupId>javax.servlet</groupId> -->
        <!-- <artifactId>servlet-api</artifactId> -->
        <!-- <version>2.5</version> -->
        <!-- <scope>provided</scope> -->
        <!-- </dependency> -->
 
        <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
 
 
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
 
        <!-- Test -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.sitemesh/sitemesh -->
        <dependency>
            <groupId>org.sitemesh</groupId>
            <artifactId>sitemesh</artifactId>
            <version>3.0.1</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.6</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.2</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-dbcp2</artifactId>
            <version>2.5.0</version>
        </dependency>
 
        <!-- 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/org.apache.commons/commons-lang3 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.8.1</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-pool2</artifactId>
            <version>2.6.0</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils -->
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.3</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/commons-collections/commons-collections -->
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.2.2</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-aop -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.7</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.3</version>
        </dependency>
        
        <!-- https://mvnrepository.com/artifact/javax.mail/mail -->
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
        </dependency>
        
        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.13</version>
        </dependency>
 
 
 
 
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <additionalProjectnatures>
                        <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                    </additionalProjectnatures>
                    <additionalBuildcommands>
                        <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                    </additionalBuildcommands>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>${java-version}</source>
                    <target>${java-version}</target>
                    <compilerArgument>-Xlint:all</compilerArgument>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                    <mainClass>org.test.int1.Main</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
 
cs

위 소스는 참고하셔서, 그대로 복사해서 붙여 넣으셔도 될 듯 합니다. 추가적으로 주석 처리된 부분은 Oracle(오라클) DB 사용 시에 필요한 부분입니다.

root-context.xml(/src/main/webapp/WEB-INF/spring/context)


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
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd
        http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd">
 
 
    <!-- @Required, @Autowired, @Qualifier, @Resource 등 어노테이션을 사용할 수 있게 설정. -->
 
    <!-- Root Context: defines shared resources visible to all other web components -->
    <context:component-scan    base-package="kr.or.infobee">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Service" />
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Repository" />
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
    </context:component-scan>
 
 
    <context:property-placeholder location="classpath:/db.properties" />
 
<!--     <bean id="spring.dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> -->
<!--         <property name="driverClassName" value="${driver}" /> -->
<!--         <property name="url" value="${url}" /> -->
<!--         <property name="username" value="${username}" /> -->
<!--         <property name="password" value="${password}" /> -->
<!--     </bean> -->
 
<!--     <alias name="dbcp2.dataSource" alias="dataSource" /> -->
 
<!--     <bean id="dbcp2.dataSource" class="org.apache.commons.dbcp2.BasicDataSource"> -->
<!--         <property name="driverClassName" value="${dev.driver}" /> -->
<!--         <property name="url" value="${dev.url}" /> -->
<!--         <property name="username" value="${dev.username}" /> -->
<!--         <property name="password" value="${dev.password}" /> -->
 
         <!-- Pool 관련 설정 -->
<!--         <property name="validationQuery" value="select 1 from dual" /> -->
<!--         <property name="maxTotal" value="300" /> -->
<!--         <property name="maxIdle" value="5" /> -->
<!--         <property name="minIdle" value="4" /> -->
<!--         <property name="defaultAutoCommit" value="false" /> -->
<!--     </bean> -->
    
    <!-- 자신의 PC(로컬)에 MySql을 설치했을 경우 -->
    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"></property>
        <property name="url"
            value="jdbc:mysql://127.0.0.1:3306/jso?useSSL=false&amp;serverTimezone=UTC">
        </property>
        <property name="username" value="jso"></property>
        <property name="password" value="oracle"></property>
    </bean>
 
    <!-- Mybatis 설정 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="configLocation"    value="classpath:/spring-mybatis-config.xml" />
        <property name="dataSource" ref="dataSource" />
        <property name="mapperLocations" value="classpath*:/mapper/*Mapper.xml" />
    </bean>
 
    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg ref="sqlSessionFactory" />
    </bean>
 
    <!-- Mapper Inferface 등록 -->
    <mybatis-spring:scan base-package="kr.or.infobee.**.impl" />
 
    <!-- 트랜잭션 매니저 등록 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
 
    <!-- 트랜잭션 AOP 적용 -->
    <tx:advice id="txAdvice"
        transaction-manager="transactionManager">
        <tx:attributes>
            <!-- 트랜잭션을 사용하지 않겠다. -->
            <tx:method name="get*" read-only="true" />
            <tx:method name="select*" read-only="true" />
            
            <!-- 트랜잭션을 사용 적용 하겠다. -->
            <!-- insertMemberItem() 이런 메소드명 -->
            <tx:method name="insert*" rollback-for="Exception" />
            <tx:method name="update*" rollback-for="Exception" />
            <tx:method name="delete*" rollback-for="Exception" />
 
            <!-- 등록 수정 삭제가 같이 있을 경우 사용 -->
            <tx:method name="put*" rollback-for="Exception" />
            
            <!-- 모든 메소드 명에 트랜젝션을 적용하겠다. -->
            <tx:method name="*" rollback-for="Exception" />
        </tx:attributes>
    </tx:advice>
 
    <aop:config>
        <aop:pointcut expression="execution(public * kr.or.infobee..impl.*(..))" id="servicePointCut" />
        <aop:pointcut expression="execution(public * kr.or.infobee.test..impl.*(..))" id="servicePointCut2" />
        <aop:advisor advice-ref="txAdvice" pointcut-ref="servicePointCut" />
    </aop:config>
 
</beans>
cs


DB 관련 설정 파일입니다. 마찬가지로 주석 처리된 부분은 Oracle(오라클) DB 사용시 필요한 부분입니다.

Oracle(오라클) DB를 사용하셔야 된다면, 아래 db.properties를 참조 해주세요.


db.properties(/src/main/resources)


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
#-----------------------------------------------------------------------
#
#   db.properties(/src/main/resources)
#
#-----------------------------------------------------------------------
 
 
 
driver=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@localhost:1521:xe
username=jso
password=oracle
 
 
dev.driver=oracle.jdbc.driver.OracleDriver
dev.url=jdbc:oracle:thin:@localhost:1521:xe
dev.username=jso
dev.password=oracle
 
 
saveRootPath=C:\Users\infobee\Desktop\attachFiles
 
 
 
 
 
 
cs

servlet-context.xml(/src/main/webapp/WEB-INF/spring/appServlet)


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
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
        
    <default-servlet-handler/>
 
    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
    
    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />
 
    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />
    <resources mapping="/fullcalendar/**" location="/fullcalendar/" />
    <resources mapping="/css/**" location="/css/" />
    <resources mapping="/fonts/**" location="/fonts/" />
    <resources mapping="/js/**" location="/js/" />
    <resources mapping="/smarteditor/**" location="/smarteditor/" />
 
    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>
    <!-- 파일 업로드로 들어오는 데이터를 처리하는 객체 -->
    <beans:bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <beans:property name="maxUploadSize" value="10485760" /<!-- 10mb 제한 -->
    </beans:bean>
        <context:component-scan base-package="kr.or.infobee">
        <context:include-filter type="annotation" 
                    expression="org.springframework.stereotype.Controller" />
 
        <context:exclude-filter type="annotation" 
                    expression="org.springframework.stereotype.Service" />
                    
        <context:exclude-filter type="annotation" 
                    expression="org.springframework.stereotype.Repository" />            
    </context:component-scan>
    
</beans:beans>
 
cs


Spring MVC 패턴에서, 모든 요청은 서블릿이 담당합니다. 그에 따른 servlet-context 설정 소스 코드입니다.


web.xml


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
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <welcome-file-list>
      <welcome-file>index.do</welcome-file>
  </welcome-file-list>
  <filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
      <param-name>forceRequestEncoding</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>forceResponseEncoding</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <url-pattern>/admin/*</url-pattern>
  </filter-mapping>
  <filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/context/*-context.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    <multipart-config>
      <max-file-size>104857600</max-file-size>
      <max-request-size>104857600</max-request-size>
      <file-size-threshold>104857600</file-size-threshold>
    </multipart-config>
  </servlet>
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>
cs


웹 프로젝트에 대한 context를 불러오고, main.decorator 사용을 하기 위해 설정하는 파일입니다.(sitemesh)


들어가기에 앞서, PrintWriter 는 Reader가 없는 오직 출력을 위한 객체입니다.

사용 빈도가 다른 Reader들에 비해 높다고 하니, 꼭 참고 하시기 바랍니다!

아래 예제는 쓰는 방법에 대해서만 설명하였으니, 응용하는 방법은 뒤에서 더 자세히 다루겠습니다.

 

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class Ex01PrintWriter {

 public static void main(String[] args) throws IOException {
  
  //PrintWriter writer = new PrintWriter(System.out,true); // Auto flush 기능
  
  PrintWriter writer = new PrintWriter(new FileWriter("/home/pc36/io/print.txt"),true); // Auto flush 기능 및 파일이 출력될 경로 지정
  
  writer.println(">>> 개인 정보 출력 <<<");
  
  writer.printf("%s, %d, %c, %s\n", "이름1", 25, 'M', "010-1234-5678");
  writer.printf("%s, %d, %c, %s\n", "이름2", 25, 'F', "010-4567-8910");
  writer.printf("%s, %d, %c, %s\n", "이름3", 35, 'M', "010-1845-9541");
  
  // writer.flush(); => Auto flush 가 true이므로 따로 입력해주지 않아도 됩니다.
  
  System.out.println("데이터 출력 완료.");  
 }
}

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Ex01ByteToChar {

 public static void main(String[] args) throws IOException {
  
  InputStreamReader reader = null;
  OutputStreamWriter writer = null;
  
  // 키보드로부터 문자 입력 받은 후 파일에 기록, (경로 지정)
  File file = new File("/home/pc36/io/memo.txt");
  
  reader = new InputStreamReader(System.in);
  writer = new OutputStreamWriter(new FileOutputStream(file));
  
  System.out.println(">>>> 메모를 남겨주세요. <<<<");
  
  char[] cbuf = new char[256]; // byte를 Char형처럼
  
  while(true) {
   int len = reader.read(cbuf); // CTRL+D(리눅스 기준)
   if(len == -1) {
    System.out.println("키보드 연결을 해제합니다.");
    break;
   }
   writer.write(cbuf,0,len);
  }
  writer.flush();
  
  System.out.println(">>>> 메세지 저장 완료. <<<<");
  
  writer.close();
 }
}

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Ex02File {

 public static void main(String[] args) throws IOException {
  SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
  
  String today = dateFormat.format(new Date());
  
  File parent = new File("/home/pc36/io", today);
  // File parent = new File("/usr/lib/io", today); // 디렉토리 생성 실패의 경우(권한이 없을 때)
  
  if(parent.exists()) {
   System.out.println("해당 디렉터리가 존재합니다.");
  }else {
   System.out.println("해당 디렉터리가 존재하지 않습니다.");
   
   if(parent.mkdirs()) {
    System.out.println(parent.getPath() + " 디렉터리 생성 완료.");
   }else {
    System.out.println(parent.getPath() + " 디렉터리 생성 실패.");
   }
  }
  
  // 파일 만들기
  File file = new File(parent, "sample2.txt");
  
  if(file.exists()) {
   System.out.println("해당 파일이 존재합니다.");
  }else {
   System.out.println("해당 파일이 존재하지 않습니다.");
   
   if(file.createNewFile()) {
    System.out.println(file.getPath() + " 파일 생성 성공");
   }
   file.setReadOnly(); // 읽기 전용
  }
 }
}

 

#자바 #File #SimpleDateFormat

 

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;

public class Ex01File {

 public static void main(String[] args) throws IOException {
  
  
 /*
  File file = new File("/home/pc36/io/sample.txt");
  File file = new File("../sample.txt");
  
  System.out.println("getName() : " + file.getName());
  System.out.println("getAbsolutePath() : " + file.getAbsolutePath());
  System.out.println("getCanonicalPath() : " + file.getCanonicalPath());
  System.out.println("getPath() : " + file.getPath());
  System.out.println("getParent() : " + file.getParent());
 */
  
  // 루트 디렉토리 목록 가져오기, 윈도우는 드라이브라는 개념을 사용하여 루트 디렉토리가 여러개다.
  // 윈도우 외에 루트 디렉토리는 하나(/)다.
  
  File[] roots = File.listRoots();
  // System.out.println(roots[0]);
  SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy년 MM월 dd일 (E) HH:mm:ss");
  
  for(int i=0; i<roots.length; i++) {
   File root = roots[i];
   File[] files = root.listFiles(); // 하위 디렉토리, 파일 목록
   
   for(File file : files) {
    // 수정일자, 유형, 파일 크기, 파일명
    System.out.printf("%s\t %s\t %s\t %s\n",
        dateFormat.format(file.lastModified()),
        file.isDirectory() ? "<DIR>" : "   ",
        (file.length()/1024) + "KB",
        file.getName()
        );
   }
  }
 }
}

 

/* 함수적 인터페이스(@FunctionalInterface)
  람다식이 하나의 메서드를 정의하기 때문에 두 개 이상의 추상 메서드를 가질 수 없다.
  하나의 추상 메서드가 선언된 인터페이스를 함수적 인터페이스(functional interface)라고
  한다.
  @FunctionalInterface 어노테이션을 붙여 사용한다. */


/* Runnable interface => FunctionalInterface */
// 익명 중첩 클래스 내에서 람다식 사용이 가능하다.

public class Ex01Lambda {

 public static void main(String[] args) {
  
  // 기존 방식
  // Thread t1 = new Thread(Runnable target)
  Thread t1 = new Thread(new Runnable() {

   @Override
   public void run() {
    System.out.println("기존 익명 중첩 클래스 방식");
   }
   
  });
  
  t1.start();
  
  // 람다식(JAVA 1.8~)
  // Thread t3 = new Thread(()-> System.out.println("람다식 방식"));
  Thread t2 = new Thread(()->{ // 한 줄이면 블럭({})을 쌓지 않아도 된다.
   System.out.println("람다식 방식");
     });
  
  
  t2.start();
 }
}

 

#자바컬렉션 #리스트 #ArrayList

 

// Vetctor (동기화 보장), ArrayList(동기화 보장 X)

import java.util.ArrayList;

public class Ex01ArrayList {

 public static void main(String[] args) {
  
  // ArrayList<E> => <E> = Generic(일반화), 타입을 결정하지 않는다.
  // ex) ArrayList<String> => 오직 String 타입만 받는다. 잘못된 데이터가 들어오는 것을 방지한다.
  
  // ArrayList list = new ArrayList(); // 오직 객체(레퍼런스) 타입만 받는다.
  // 자바 1.5 버전 이후부터 <E>(GENERIC) 사용 가능
  ArrayList<String> list = new ArrayList<String>(); // 오직 String 타입만 받는다.
  
  list.add("가");
  list.add("나");
  list.add(new String("다"));
  list.add(new String("라"));
  
  // list.add(new Integer(50));
  
  System.out.println(list); // 순서의 개념이 존재.
  
  list.add("나");
  System.out.println(list); // 데이터의 중복이 가능하다.
  
  if(list.contains("다")) { // 존재 여부
   // System.out.println("존재합니다.");
  }else {
   // System.out.println("존재하지 않습니다.");
  }
  
  
  if(list != null && !list.isEmpty()) { // list가 null이 아니고 list가 비어있지 않아야함.
   int size = list.size(); // 메서드를 직접 호출하는 것보다 변수로 설정하여 호출하는 것이 좋다.
   for(int i =0; i<size; i++) { // 데이터 순차 접근
    //  String name = (String)list.get(i);
    String name = list.get(i); // 형 변환을 하지 않아도 된다.
    System.out.println(name);
    
   }
  }
  System.out.println("====================");
   // Advanced For, forEach
   // 순차 출력의 경우 장점 크다.
   // 자바 1.5 버전 이후부터 <E>(GENERIC) 사용 가능
   for(String name : list) { // list에 담겨있는 값을 하나씩 꺼내 String name에 담는다. 
    System.out.println(name);
   }
  
 }
}

 

 public static void main(String[] args) {
  // SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy년 MM월 dd일 a hh시 mm분 ss초 SSS");
  // SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd E요일");
  
  Date date = new Date(); // 현재 시간, 표준
  System.out.println("date : " + date);
  
  String strDate = dateFormat.format(date);
  System.out.println("strDate : " + strDate);
 }

 

#year #month #Calendar #BufferedReader #for

 

 public static void main(String[] args) throws NumberFormatException, IOException {
  
  
  
  // 년와 월을 입력 받아 달력을 출력
  BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
  
  System.out.print("년을 입력해주세요 : ");
  int year = Integer.parseInt(read.readLine());
  
  System.out.print("월을 입력해주세요 : ");
  int month = Integer.parseInt(read.readLine());
  
  Calendar cal = Calendar.getInstance(); // 현재 날짜와 시간
  
    // 해당 월의 첫번째 날짜의 요일
    // DAY_OF_WEEK
    cal.set(year, month-1, 1);
    int dayOfweek = cal.get(Calendar.DAY_OF_WEEK)-1; // 1~7 -> 0~6
    // int dayOfweek = (lastYear + leapYear_cnt + dayOfYear)%7;
   
    
    // 월에 따른 날짜 출력 조건
    // getActualMAXIMUM -> 현재 객체의 최대값 반환 / getMAXIMUM -> 전체 중, 최대값만 반환
    int lastday = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
    
    System.out.printf("                     %d년 %02d월\n", year, month);
    System.out.printf("일\t월\t화\t수\t목\t금\t토\n");
    
    // 공백 출력
    for(int i =0; i<dayOfweek; i++) {
     System.out.print("\t");
    }
    // 날짜 출력
    for(int i = 1; i<=lastday; i++) {
     System.out.print(i + "\t");
     if((dayOfweek+i)%7 ==0) {
      System.out.println();
     }
    }

    
 }

리눅스 민트(Linux Mint) 다운로드 링크 : https://www.linuxmint.com/download.php

 

 

<사용한 프로그램>

 

VM VirtualBox : https://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html

 

VM VirtualBox 확장팩 : https://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html#extpack

 

세 가지 모두 다운로드를 받으셨다면 VM VirtualBox를 설치 해줍니다.

VM VirtualBox 설치에 대한 가이드는, 따로 첨부할 필요성을 느끼지 못하여 첨부하지 않겠습니다.

 

1) 세 가지 모두 다운로드를 마치셨다면, 이제 VM VirtualBox를 실행해 봅시다.

저는 이미 설치가 완료된 상태라서, mint 정보가 있네요. 아래 민트는 무시하고, 설치 가이드 시작합니다!

 

2) 먼저 위에서 설치한 확장팩을 등록 해주도록 하겠습니다.

파일(F) - 환경설정 - 확장으로 가서 오른쪽에 보이는 + 모양 클릭 후 다운로드 받은 확장팩을 등록 설치 해줍시다. 설치가 끝났다면 확인을 눌러주세요.

 

3) 이번엔 본격적으로, 리눅스 민트를 설치할 차례입니다. 리눅스 민트를 설치하기 위해 새로 만들기(N) 을 클릭해주세요.

저는 현재 mint 연결이 있으니 이름을 mint2 로 하여 설치를 진행하겠습니다. 다음(N) 클릭

 

4) 다음은 메모리 설정입니다. 자신의 컴퓨터에서 쓰고 있는 RAM에서 할당 받는 메모리이니 적당하게 설정 후 다음으로 넘어 가주세요.

저는 2GB 정도 설정 했습니다.

 

5) 다음은 가상 하드 디스크 설정입니다. 최초 설치 후 실행하신 분들은 고민 할 필요 없이 두 번째 클릭 후 다음으로 넘어 가주세요.

 

6) 다음은 하드 디스크 파일 종류 선택입니다. 특별한 사항이 없다면 체크된 곳에 체크를 하시고 다음으로.

 

7) 더 볼 것도 없이 동적 할당 체크 후 넘어갑시다.

 

8) 다음은 새 가상 하드 디스크의 용량을 정하는 부분입니다. 이것 역시 사용자의 입맛에 맞게 설정해주세요.

저는 약 20GB 정도 설정했습니다.

 

9) 자 모두 설정 후 만들었다면 mint2 가 생성 됐을겁니다. 저는 예시를 위해 생성하는 척만 했을뿐 실제로 생성은 하지 않았습니다. (^^;;)

아무튼, 생성이 다 되었다면 이제 생성된 VM에 운영체제를 설치해야겠죠?

아까 받아 놓은 리눅스 민트.iso 파일을 불러 줍시다!

mint 오른쪽 마우스 클릭 -> 설정 -> 저장소 -> 컨트롤러 : IDE 에서 CD 모양(+) 클릭 후 받아 놓은 iso 파일을 등록한 뒤, 확인을 눌러주세요.

그리고 이제 mint 의 전원을 켜주시면 끝입니다!

 

10) 시작을 눌러서 리눅스 민트가 정상적으로 로드 되면 성공입니다.

혹시, VM을 실행했는데 그래픽이 깨진다면 아래의 해결 방법으로 해결해보세요.

 

- VirtualBox로 우분투를 설치할 때 그래픽이 꺠진다. 몇백 픽셀밖에 보이지 않는다.
CTRL ALT F1을 눌러 tty1을 연 후 CTRL ALT F7을 눌러주면 된다.

 

11) 리눅스 민트까지 모두 설치 완료한 최종 화면입니다.

 

별도 첨부) 리눅스 설치 가이드

 

 

 

 

+ Recent posts