일반적으로 Database Connection을 가져오지 못하면 Cannot create PoolableConnectionFactory  Exception이 발생한다.


그리고 쿼리작성 문법에 오류가 나면 (ORA-00923: FROM 키워드가 필요한 위치에 없습니다.) 등의 오류가 발생한다.


근데 DB에 연결도 못했는데 문법오류가 나는 경우가 있다.


물론 연결 접속정보나 이런것들 방화벽 다 확인해보았지만 모두다 정상인 상태이다.


org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (ORA-00923: FROM 키워드가 필요한 위치에 없습니다.)


이경우는 Spring Framework의 설정부분 중 validationQuery를 확인해 보아야한다. 


환경설정을 할 때 DB 종류가 바뀌는 경우 접하는 경우가 대부분이다.


1
2
3
4
5
6
7
8
 
 
// HashSet과 LinkedHashSet의 차이는 중복이 제거 될 때 HashSet은 기존 리스트의 구성요서의 순서가 지켜지지 않는다 
 
List<String> uniqueItems = new ArrayList<String>(new HashSet<String>(returnitems));
 
 
List<String> uniqueItems = new ArrayList<String>(new LinkedHashSet<String>(returnitems));
cs


 

List에 내용물이 String이나 int가 아닌 경우 정렬

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
ArrayList<HashMap<StringString>> items = new ArrayList<HashMap<StringString>>();
 
 
Collections.sort(items, new Comparator<HashMap<StringString>>() {
            @Override
            public int compare(HashMap<StringString> first, HashMap<StringString> second) {
                
                int firstValue = Integer.valueOf(first.get("ORDER_BY"));
                int secondValue = Integer.valueOf(second.get("ORDER_BY"));
 
                if (firstValue > secondValue) {
                    return -1;
                } else if (firstValue < secondValue) {
                    return 1;
                } else /* if (firstValue == secondValue) */ {
                    return 0;
                }
                
            }
        });
cs

 

 

물론 비교를 compareTo로 해도 되긴하는데 내경 우에는 700 60 500의 값이 비교될 때 

 

60이 500보다 우선순위로 정렬되는 기이현상으로 인하여 

 

if else if로 구현하였음

※ Spring Frame Work 3.2 기준 실제 사용 했던 Servlet.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
<?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:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" 
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:util="http://www.springframework.org/schema/util" 
    xmlns:task="http://www.springframework.org/schema/task" 
    xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
        http://www.springframework.org/schema/task
        http://www.springframework.org/schema/task/spring-task-3.2.xsd">
        
 
 
 
    <!-- The controllers are autodetected POJOs labeled with the @Controller, @Service, @Component annotation. -->
    <!-- @Controller, @Service, @Component annotation 아래의 package를 스켄하여 @Autowired 
        어노테이션을 이용하여 해당하는 엔티티 및 서비스를 맵핑한다. -->
    <!-- <context:component-scan base-package="com.isource.web.controller, com.isource.domain.service, 
        com.isource.web.validator, com.isource.web.security"/> -->
        
        
        
        
    
    <context:component-scan base-package="com.myPackage.web" />
    <mvc:resources location="/WEB-INF/resources/" mapping="/resources/**" />
 
 
    <context:annotation-config></context:annotation-config>
<!--     <task:executor id="taskExecutor" pool-size="5"/>
    <task:annotation-driven executor="taskExecutor"/> -->
    
    
 
    <!-- Annotation 기반 트랜잭션 설정 -->
    <tx:annotation-driven transaction-manager="oracleTransactionManager" />
 
    <!-- 트랜잭션 매니저 -->
    <bean id="oracleTransactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
 
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation" value="classpath:/mybatis/mybatisConfig.xml" />
        <property name="mapperLocations" value="classpath:/mybatis/sql/**/*.xml" />
    </bean>
 
    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg index="0" ref="sqlSessionFactory" />
    </bean>
    <bean id="sqlBatchSession" class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg index="0" ref="sqlSessionFactory" />
        <constructor-arg index="1" value="BATCH" />
    </bean>
 
    <bean id="anotherTransactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="anotherDataSource" />
    </bean>
 
    <bean id="anotherSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="anotherDataSource" />
        <property name="configLocation" value="classpath:/mybatis/mybatisConfig_another.xml" />
        <property name="mapperLocations" value="classpath:/mybatis/sql_another/**/*.xml" />
    </bean>
 
    <bean id="anotherSqlSession" class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg index="0" ref="anotherSqlSessionFactory" />
    </bean>
    
    <bean id="anotherBatchSqlSession" class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg index="0" ref="anotherSqlSessionFactory" />
        <constructor-arg index="1" value="BATCH" />
    </bean>
 
    <!-- Validation 활성화(validator="validator"), conversionService 활성화, 메세지 컨버터 
        등록 (JSON을 바꿔주는부분) -->
    <mvc:annotation-driven conversion-service="conversionService">
        <mvc:message-converters>
            <bean
                class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
                <property name="objectMapper">
                    <bean class="com.myPackage.web.converter.CustomObjectMapper" />
                </property>
            </bean>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>text/html;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>
 
    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/**" />
            <mvc:exclude-mapping path="/login**" />
            <mvc:exclude-mapping path="/login*" />
            <mvc:exclude-mapping path="/loginform**" />
            <mvc:exclude-mapping path="/resources/**" />
            <mvc:exclude-mapping path="/*.ico" />
            <bean class="com.isource.web.controller.IsourceInterceptor" />
        </mvc:interceptor>
 
        <bean id="localeChangeInterceptor"
            class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
            <property name="paramName" value="convertLocale" />
        </bean>
    </mvc:interceptors>
    
    
    <bean id="localeResolver"
        class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
        <property name="defaultLocale" value="ko" />
    </bean>
    
 
    <!-- Configure the multipart resolver -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
            <!-- one of the properties available; the maximum file size in bytes about 
            10MB -->
        <property name="maxUploadSize" value="10000000" />
    </bean>
    <alias name="multipartResolver" alias="multipartResolver" />
 
    <!-- Configure the file upload directory -->
    <!-- <bean id="uploadDirResource" class="org.springframework.core.io.FileSystemResource"> 
        <constructor-arg> <value>C:/myPackage/upload/</value> </constructor-arg> </bean> -->
 
    <!-- tiles 2에서 전부처리되어 주석처리됨. <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:order="2" p:prefix="/WEB-INF/views/" p:suffix=".jsp"/> -->
 
    <bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver" p:order="1" p:viewClass="org.springframework.web.servlet.view.tiles2.TilesView" />
    <bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer" id="tilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tiles/tiles-def.xml</value>
            </list>
        </property>
    </bean>
 
    <!-- @Valid 에서 스프링의 Message.properties를 사용하기 위해 추기 -->
    <bean id="validator"
        class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
        <property name="validationMessageSource" ref="messageSource" />
    </bean>
 
    <!-- Message -->
    <bean id="messageSource"
        class="com.myPackage.extendz.IscReloadableResourceBundleMessageSource">
        <!-- class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> -->
        <property name="defaultEncoding" value="UTF-8" />
        <property name="basenames">
            <list>
                <value>classpath:/messages/messages</value>
                <value>classpath:/messages/buttons</value>
                <value>classpath:/messages/labels</value>
            </list>
        </property>
    </bean>
 
    <!-- Exception 처리 -->
    <bean
        class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver">
        <property name="order" value="1" />
    </bean>
    
    
    <bean
        class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
        <property name="order" value="2" />
        <property name="defaultErrorView" value="/common/error500" />
        <!--.main 은 타일즈 standalone layout 적용 -->
    </bean>
 
 
    <!-- Conversion Service 기본 포멧터 사용 -->
    <bean id="conversionService"
        class="org.springframework.format.support.FormattingConversionServiceFactoryBean" />
 
    <bean id="logDataSource_pos" class="net.sf.log4jdbc.Log4jdbcProxyDataSource">
        <constructor-arg ref="dataSource" />
        <property name="logFormatter">
            <bean class="net.sf.log4jdbc.tools.Log4JdbcCustomFormatter">
                <property name="loggingType" value="MULTI_LINE" />
                <property name="sqlPrefix" value="SQL=>" />
            </bean>
        </property>
    </bean>
 
 
    <!-- Quartz -->
    <bean id="batchService" class="com.myPackage.schedule.quartz.job.service.BatchService" />
    <bean id="sapJcoTransfer" class="com.myPackage.schedule.quartz.job.transfer.SapJcoTransfer" />
    <bean id="procedureTransfer" class="com.myPackage.schedule.quartz.job.transfer.ProcedureTransfer" />
    
 
     <bean name="isourceJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean" p:jobClass="com.isource.schedule.quartz.job.IsourceQuartzJobBean" p:durability="true">
        <property name="jobDataAsMap">
            <map>
                <entry key="batchService" value-ref="batchService" />
            </map>
        </property>
    </bean>
 
    <!-- <bean id="cronTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean" p:jobDetail-ref="isourceJob" p:startDelay="0" p:cronExpression="0/10 * * * * ?" /> -->
    
    <bean id="SimpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
        <property name="jobDetail" ref="isourceJob" />
        <property name="startDelay" value="0" />
        <property name="repeatInterval" value="604800000" /
    </bean>
    
          
          
          
          
    <bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="SimpleTrigger" />
            </list>
        </property>
    </bean>
    <bean class="com.myPackage.common.util.ApplicationContextAwareExtends"/>
    
    
    
    <bean class="com.myPackage.common.helper.mail.MailSendWorker">
        <constructor-arg>
            <ref bean="naverMailSender" />
        </constructor-arg>
    </bean>
    
    <!-- Gmail setting -->
    <bean name="gmailMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"
            p:password="input your password"
            p:host="smtp.gmail.com"
            p:port="587"
            p:protocol="smtp"
            p:username="input your account"
            p:defaultEncoding="utf-8">
        <property name="javaMailProperties">
            <props>
                <prop key="mail.smtp.ssl.enable">false</prop>
                <prop key="mail.smtp.starttls.enable">true</prop>
                <prop key="mail.smtp.ssl.trust">*</prop>
                <prop key="mail.smtp.port">587</prop><!-- mail.smtp.ssl.enable true인 경우 주석처리후 사용 -->
                <prop key="mail.smtp.auth">true</prop>
                <prop key="mail.debug">true</prop>
            </props>
        </property>
    </bean>
    
    <!-- naver setting -->
    <bean name="naverMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"
            p:password="input your password" 
            p:host="smtp.naver.com"
            p:port="465"
            p:protocol="smtps" 
            p:username="input your account"
            p:defaultEncoding="utf-8">
        <property name="javaMailProperties">
            <props>
                <prop key="mail.smtp.starttls.enable">true</prop>
                <prop key="mail.smtp.auth">true</prop>
                <prop key="mail.smtp.ssl.enable">true</prop>
                <prop key="mail.smtps.ssl.checkserveridentity">true</prop>
                <prop key="mail.smtps.ssl.trust">*</prop>
                <prop key="mail.debug">false</prop>
            </props>
        </property>
    </bean>
    
    <!-- Local Stmp setting -->
    <bean name="customMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"
            p:host="smtp.mailplug.co.kr"
            p:protocol="SSL"
            p:defaultEncoding="utf-8">
        <property name="javaMailProperties">
            <props>
                <prop key="mail.smtp.port">465</prop>
                <prop key="mail.smtp.starttls.enable">false</prop>
                <prop key="mail.smtp.ssl.enable">true</prop>
                <prop key="mail.smtp.ssl.trust">*</prop>
                <prop key="mail.smtp.auth">true</prop>
                <prop key="mail.debug">true</prop>
            </props>
        </property>
        <!-- <property name="username" value="customSTMPUser"/>
        <property name="password" value="customSTMPPassword"/> -->
 
    </bean>
    
 
</beans>
 
cs


 

selectkey를 사용하여 키를 생성하면서 CUD 작업을 진행할 경우 생성한 key를 가져오지 못하는 경우가 있습니다. 

 

이 경우 간단한 이유인데요 보통 개발하실 때 복사하기 붙여 넣기만 하다가 해당 기능의 각 속성들의 기능을 잘 파악하지 못하여 발생하는 문제입니다. 

 

 

<insert id="queryId" parameterType="java.util.Map">
<selectKey keyProperty="id" resultType="java.lang.String">

 

SELECT #{CUODE} ||#{DIE}|| #{I11TH} FROM DUAL

 

</selectKey>

 

MERGE INTO MY_TABLE SM
USING (SELECT #{id} SALES_NO
,#{AA} AA
,#{BB} BB
,#{CC} CC
FROM DUAL) MG
ON
......
....
..

</insert>

 

 

 
위 의 소스의 경우 id 값을 가지고 오지못하고 해당 값이 Not Null 이라면 오라클 익셉션이 발생합니다.
selectkey의 각 속성값을 살펴보면 다음과 같습니다.
 
Attribute Description
keyProperty The target property where the result of the 
selectKey statement should be set.
Can be a comma separated list of property names if multiple generated columns are expected.
keyColumn The column name(s) in the returned result set that match the properties.
Can be a comma separated list of column names if multiple generated columns are expected.
resultType The type of the result. MyBatis can usually figure this out, but it doesn't hurt to add it to be sure.
MyBatis allows any simple type to be used as the key, including Strings.
If you are expecting multiple generated columns, then you can use an Object that contains
the expected properties, or a Map.
order This can be set to BEFORE or AFTER.
If set to BEFORE, then it will select the key first, set the keyProperty and then execute
the insert statement. If set to AFTER, it runs the insert statement and
then the selectKey statement – which is common with databases like Oracle
that may have embedded sequence calls inside of insert statements.
statementType Same as above, MyBatis supports STATEMENTPREPARED and CALLABLE statement types
that map to StatementPreparedStatementand CallableStatement respectively
 
 
 
해당 문제를 해결하기 위해서 확인해야 할 것은 order 속성입니다. 
ORDER 속성은 BEFORE 와 AFTER를 선택할 수 있는데 해당 속성을 정의하지 않을경우 기본값이 AFTER입니다. 
BEFORE는 INSERT 문을 실행하기전 selectkey 구문을 수행하고 AFTER는 INSERT문을 수행한 후 selectkey가 수행됩니다. 
 
즉 올바른 동작을 위해서는 아래 예제와 같이 코드가 작성되어야 합니다. 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<insert id="queryId" parameterType="java.util.Map">
        <selectKey keyProperty="id" resultType="java.lang.String" order="BEFORE">
        SELECT #{ASDFAS} ||#{SDF}|| #{INVASDFONTH} FROM DUAL
        </selectKey>
        MERGE INTO MY_TABLE SM
        USING (SELECT #{id} SALES_NO
                     ,#{AA} AA
                     ,#{BB} BB
                     ,#{CC} CC
                 FROM DUAL) MG 
           ON
        ......
        ....
        ..
<insert>
cs

 

Mybatis를 이용하여 프로젝트 진행 시 아래와 같은 Exception이 발생하는 경우가 있습니다. 



java.sql.SQLException: 허용되지 않은 작업



이 경우는 sqlSession 객체가 배치타입으로 설정되어 있어서 프로시저를 호출 할 수 없는 경우입니다. 


mybatis의 배치 관련 설정하는 곳은 대표적으로 두군대를 볼 수 있습니다. 


각 설정 파일은 환경에 따라 파일명이 상이 할 수 있으므로 아래와 같이 설명하도록 하겠습니다. 


1. 스프링 설정 xml 

  <bean id="sqlBatchSession" class="org.mybatis.spring.SqlSessionTemplate">

<constructor-arg index="0" ref="sqlSessionFactory" />

<constructor-arg index="1" value="BATCH" />

</bean> 



붉은색 항목이 존재할 경우 모든 DB관련 작업은 배치 형태로 수행하게 됩니다. (ibatis의 executeBatch 와 동일)  

해당 부분을 삭제 하면 정상적으로 프로시저 호출이 가능합니다. 


2. mybatis 설정 xml 

  <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

<property name="dataSource" ref="dataSource" />

<property name="configLocation" value="classpath:/mybatis/mybatisConfig.xml" />

<property name="mapperLocations" value="classpath:/mybatis/sql/**/*.xml" />

</bean> 


붉은색 부분에 설정한 Mybatis 설정파일의 내용을 확인해 볼 필요가 있습니다. 


<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "HTTP://mybatis.org/dtd/mybatis-3-config.dtd">


<configuration>

<settings>

<setting name="cacheEnabled" value="true" />

<setting name="jdbcTypeForNull" value="VARCHAR"/>

<setting name="defaultExecutorType" value="BATCH"/>

</settings>

<!-- Type aliases -->

<typeAliases />


<!-- Mappers -->

<mappers />

</configuration> 


붉은색으로 표시된 설정항목이 존재할 경우 스프링 설정.xml에서 <constructor-arg index="1" value="BATCH" /> 가 없더라도 배치형태로 수행 하게 됩니다. 


sqlSession 객체를 일반 형태와 배치형태로 두개의 빈을 등록해 사용하길 권장드립니다. 


당연히 배치관련 옵션은 스프링설정.xml에서 배치형태로 설정하시고 Mybatis설정 파일에서는 해당 설정값을 제거 하시고 사용하시는걸 추천드립니다. 



스프링설정.xml에서 관리하는 내용의 예제 소스

<bean id="oracleTransactionManager"

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

<property name="dataSource" ref="dataSource" />

</bean>


<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

<property name="dataSource" ref="dataSource" />

<property name="configLocation" value="classpath:/mybatis/mybatisConfig.xml" />

<property name="mapperLocations" value="classpath:/mybatis/sql/**/*.xml" />

</bean>


<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">

<constructor-arg index="0" ref="sqlSessionFactory" />

</bean>

<bean id="sqlBatchSession" class="org.mybatis.spring.SqlSessionTemplate">

<constructor-arg index="0" ref="sqlSessionFactory" />

<constructor-arg index="1" value="BATCH" />

</bean>




오늘은 Mybatis를 사용하면서 당황할 수 있는 예제를 설명 드립니다. 


xml 을 작성할 경우 if 문을 사용할 떄 java.lang.NumberFormatException이 발생하는 경우가 있습니다. 


버그인지 모르겠으나 비교대상이 1자리 일 경우 해당 에러가 발생합니다. 


예를 들어보겠습니다. 


select

       col01,col02,col03,col03 ......

        ....

   from dummytable

where 1=1

<if test="compare_col =' '  and  compare_col != 'A'">

   and col2 = #{compare_col}

</if> 


위의 예시와같이 ' ' 혹은 'A' 같은경우 즉 1자리의 텍스트의 경우  java.lang.NumberFormatException 이 발생하고는 합니다.


해결방법은 


<if test='compare_col =" "  and  compare_col != "A"' >


test의 값을  ''로 감싸고 각 값들을 ""로 사용할경우 해당 Error을 피할 수 있습니다


다른방법도 있습니다. 'A'.toString() 으로 변경하여 사용하셔도 됩니다만 저는 전자의 경우가 더 편하기떄문에 ""로 변경하는것을 추천드립니다. 



Quartz 1.6.4 version → Quartz to 2.1.6 version 으로 변경시 변경 사항



※ getName(), getGroup()

Quartz to 2.1.6 version 에서 jobDetail()에서 getName() 혹은 getGroup() 을 수행할경우 해당 method를 지원하지 않아 오류가 나게 됩니다. 


Quartz to 2.1.6 version에서는 다음과 같이 사용할 수 있습니다. 

 

String jobName = jobExecutionContext.jobDetail().getKey().getName();

String jobGroup = jobExecutionContext.jobDetail().getKey().getGroup();




※ JobDetail

Quartz to 2.1.6 version 에서 JobDetail 을 생성할 때  


Quartz to 2.1.6 version에서는 다음과 같이 사용할 수 있습니다. 

 

                 <1.x.x> 

                 JobDetail jobDetail = new JobDetail(jobName, jobGroup, classForName(jobClass));

                 <2.x.x>

JobDetail jobDetail = JobBuilder.newJob(classForName(jobClass)).withIdentity(jobName, jobGroup).build();



※ CronTrigger

Quartz to 2.1.6 version 에서 CronTrigger을 생성할 때  


Quartz to 2.1.6 version에서는 다음과 같이 사용할 수 있습니다. 

 

                 <1.x.x> 

                 CronTrigger cronTrigger = new CronTrigger(triggerName, triggerGroup);

                 CronExpression cexp = new CronExpression(cronExpress);

cronTrigger.setCronExpression(cexp);

                 <2.x.x>

Trigger trigger = TriggerBuilder.newTrigger().withIdentity(triggerName, triggerGroup).withSchedule(CronScheduleBuilder.cronSchedule(cronExpress)).build();


<변경사항에 대한 내용 계속 추가 예정>

개요 

SSL 인증서를 설치하고 난 뒤 성공하여 테스트를 진행할 경우 https를 붙여 테스트를 합니다.

하지만 여기서 우리가 간과한 것이 있습니다. 해당 페이지는 https로만 페이지가 열려야하는데 http로도 열리게 됩니다. 

이렇게 되어서는 인증서를 적용한 의미가 없지요 그래서 Spring-security의 일부 기능을 이용하여 지정된 페이지 혹은 URL Pattern에 따라 강제로 https로 열리게 할 수 있는 기능을 구현하도록 해봅시다.



준비물 


저는 구성되어 있는 환경이 Spring 3.2 이므로 Spring-security도 3.2로 구성하도록 하겠습니다. 


1. Spring Framework 3.2 환경

2. Spring-security 3.2 jar  ( 예제에 사용된 라이브러리 - spring-security-3.2.0.M1.zip


   (maven을 사용하지 않는경우는 블로그를 참조하여 파일을 준비합니다. http://cheezred.tistory.com/123)


환경 설정


우리가 작업할 파일은 수정할 web.xml 파일과 신규로 생성할 spring-security.xml 입니다. 

먼저 spring-security.xml을 먼저 생성합니다. 일반적으로 해당 파일의 위치는 Spring Framework 설정파일과 같은 위치에 생성합니다. 

- spring-security.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:security="http://www.springframework.org/schema/security"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
           http://www.springframework.org/schema/security
           http://www.springframework.org/schema/security/spring-security-3.1.xsd">
 
        
         <security:http pattern="/resources/**" security="none" />
         
         <security:http auto-config="true">
             <security:intercept-url pattern="/**" requires-channel="https" />
         </security:http>
 
        <security:authentication-manager></security:authentication-manager>
 
</beans>
 
cs


>> Source Detail

<security:http pattern="/resources/**" security="none" />

=> url pattern이 /resources/로 시작되는 요청은 spring security 를 적용하지 않음


<security:intercept-url pattern="/**" requires-channel="https" />

=> 모든 요청에 대해서 https 통신을 적용하겠다 라는 내용입니다.

여러 패턴을 구성하여 http 및 https를 구분하여 페이지를 요청 할 수 있습니다.




- web.xml #1

1
2
3
4
5
6
7
8
9
10
11
<!-- Spring Security Start -->    
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
<!-- Spring Security End -->
cs


>> Source Detail

위의 부분을 web.xml에 추가합니다. 주의할 점이 있는데 springSecurityFilterChain 이름을 변경하지 마시기 바랍니다. 클래스를 못찾는 오류가 발생합니다. 


- web.xml #2

1
2
3
4
5
6
7
<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/spring/datasource.xml
            /WEB-INF/spring/spring-security.xml
        </param-value>
</context-param
cs
>> Source Detail

위의 붉은색 항목을 web.xml에 추가합니다. 위에서 작성한 spring-security.xml을 WAS 기동 시 적용시키기 위함입니다. 

주의 할점은 web.xml에 DispatcherServlet 항목이 있는데 그곳에 추가하시는 것이 아니라는 것입니다. 

contextConfigLocation 항목이 없으신 경우 추가하셔서 붉은색 부분을 넣으시면 됩니다.

작성자는 contextConfigLocation를 사용하고 있어 붉은색 부분을 추가한 부분입니다.



테스트

- https로 호출되어야 하는 페이지를 http로 호출해 봅니다. https로 변환되어 페이지가 열리면 올바르게

설정되었다고 할 수 있습니다.




웹사이트에 Spring security에 대한 글이 많습니다. 아래 소개한 기능외에 많은 기능이 있습니다. 작성자는 https로 페이지를 분기하기 위한 기능만 사용한 예시 입니다.  해당 글들을 다수 정독하였지만 올바르게 작성된 글이 없어 실제 사용된 소스를 기반으로 작성되었습니다. 

'Development > Java' 카테고리의 다른 글

[Mybatis] java.lang.NumberFormatException 발생  (0) 2017.04.20
[Quartz] 1.x.x 사용하다 2.x.x로 변경 시 변경된 메서드  (0) 2017.03.16
Jar File Download Site  (2) 2016.12.20
Spring과 Quartz 연동  (0) 2016.10.27
Java Locale List  (0) 2016.08.31


Site Url : http://grepcode.com/

+ Recent posts