전자정부프레임워크을 이용해서 웹 애플리케이션을 개발하면 통상적으로 MVC 모델 형태로 개발을 하게 된다.
이때 Controller 클래스(@Controller가 붙여지는 클래스)에 각종 사용자의 request 처리하는 코드가 모이게 된다.
따라서 request 관련을 살펴봐야 한다면 Controller 클래스만 보면 되므로 한 자리에서 파악할수 있는 잇점이 있어 편리하다.
그런데 Spring 프레임웤이 Controller 클래스를 인식하도록 할려면 환경을 어떻게 설정해야 하는가?
물론 전자정부프레임웤에서
eGovFrame - Start - New Web Project - Project name과 Group Id 설정 후 - Next - Generate Example 창에서
"Generate Example"을 체크하게 되면 전자정부프레임웤에서 모든 환경설정을 해주게 되고 Controller 클래스가 정상적으로 인식이 된다.
그러나 만일 전자정부프레임웤의 기본 환경설정과 다르게 설정하기 원한다거나 그렇게 디폴트로 생성된 파일들 등을 사용하기 원치않는다면 이때 어떻게 설정해야
Controller 클래스를 인식하게 할수 있을까?
이에 대한 환경 설정에 대해서 정리해 보고자 한다.
본 포스트는 이해를 수이하기 위해서 DB 설정은 제외하고 순전히 Controller 클래스의 등록에 대한 부분만 다룬다.
eGovFrame - Start - New Web Project - Project name과 Group Id 설정 후 - Next - Generate Example 창에서 - "Generate Example"을 체크해제 - Finish
이렇게 프로젝트를 생성해서 아래와 같이 해당 프로젝트를 실행하면 404 에러를 출력하는 페이지만 보일 것이다(프로젝트명이 TestTest라고 하자).
http://localhost:8081/TestTest/
그렇다고 프로젝트가 잘못 생성된 것은 아니다. 확인하기 위해서 간단하게 index.jsp를 생성해서 실행해 보자.
해당 프로젝트의 src/main/webapp/ 아래에 index.jsp를 생성해야 한다. 중요한것은 webapp 폴더가 Root 폴더로 인식되기 때문이다.
Webapp 폴더에서 마우스 우측 클릭 - New - JSP File - File name을 index.jsp로 지정 후 Finish
<body> 태그 안에
<h2>Hello world. I am index.jsp</h2>
를 추가후 해당 프로젝트 명에서 우측 클릭 후 Run As - Run on Server - Finish
정상적으로 index.jsp의 내용이 보일것이다.
이제부터 Controller 클래스가 인식되도록 환경 설정을 할 것이다. 우선 web.xml 파일을 아래의 내용과 같이 설정 내용을 작성한다.
최초 web.xml에는 아래의 내용만 되어 있을 것이다.
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
아래는 web.xml의 Controller 클래스가 인식되도로 하기 위한 기본 설정 내용이다.
*** web.xml의 기본 설정 내용 ***
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>MyTest</display-name>
<!-- 인코딩 관련 -->
<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>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<!-- 크로스 스크립팅이라는 해킹 기법을 사전에 막는 기능. -->
<filter>
<filter-name>HTMLTagFilter</filter-name>
<filter-class>egovframework.rte.ptl.mvc.filter.HTMLTagFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HTMLTagFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<!-- 어떤 객체들을 미리 만들어 놓을지가 작성된 설정 파일의 경로를 값으로 할당 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<!-- Spring 환경설정 파일인 context-*.xml을 읽은다.
src/main/resources/egov/spring/context-*.xml을 의미한다. -->
<param-value>classpath*:egov/spring/context-*.xml</param-value>
</context-param>
<!-- -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- MVC에서 Controller 역할을 하게 될 DispatcherServlet 객체 등록.
*.do라는 요청이 들어오면 appServlet이름의 서블릿 클래스인
org.springframework.web.servlet.DispatcherServlet를 실행한다.
DispatcherServlet 클래스에 대한 설정 내용은 /WEB-INF/spring/appServlet/dispatcher-servlet.xml에
설정되어 있다.
-->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
아래는 context-root.xml을 설정내용인데 현재 시점에서는 아래와 같이 파일만 생성해 둔다.
*** context-root.xml 설정 내용 ***
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
</beans>
아래는 DispatcherServlet을 위한 환경 설정이다.
*** dispatcher-servlet.xml 환경 설정 내용 ***
<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<!-- xmlns:mvc="http://www.springframework.org/schema/mvc" -->
<!-- annotation을 사용하도록 설정 -->
<mvc:annotation-driven /> <!-- 근데 이것 없이도 정상적으로 동작함 -->
<!--
base-package는 src/main/java/ 하위에 있는 패키지 명 중에서 ""안에 지정한 패키지 이하를 스캔하라는 뜻임.
즉 base-package="egovframework"라고 하면
egovframework.example.cmmn
egovframework.example.cmmn.web
egovframework.example.sample.service
egovframework.example.sample.service.impl
egovframework.example.sample.web
모두가 다 해당된다.
base-package="egovframework.example"과 같이 해도 된다.
다음과 같은 식으로도 가능
<context:component-scan base-package="com.yk.yboard, com.yk.common"/>
아래는 버스앱의 경우에 대한 것이다.
<context:component-scan base-package="com.hubizict.bus" />
<context:include-filter type="" expression=""/>는 자동 스캔 대상에 포함시킬 클래스를 의미
<context:exclude-filter type="" expression=""/>는 자동 스캔 대상에 포함시키지 않을 클래스를 지정하는 의미
-->
<context:component-scan base-package="com.joe">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
<context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>
<context:include-filter type="annotation" expression="org.springframework.stereotype.Component"/>
</context:component-scan>
</beans>
이상의 작업을 통해서 eGov 프레임워크가 Controller 클래스를 인식하도록 설정이 되었다.
이제 Controller 클래스를 간단하게 만들어 보자. 해당 프로젝트의 src/main/java/ 아래에 패키지를 만든다.
src/main/java/ 위에서 마우스 우측 클릭 - New - Package
패키지 이름을 com.joe.egov.test를 만들어 보자.
생성된 패키지명 위에서 마우스 우측 클릭 - New - Class - MyController로 컨트롤러 클래스를 만들자.
이제 MyController 클래스를 다음과 같이 작성해 보자.
package com.joe.egov.test;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class MyController {
@RequestMapping(value="/mytest.do", method=RequestMethod.GET)
public String test(){
System.out.println("####### Hello this is MyController 클래스 ");
return "test.jsp";
}
}
이제 webapp 폴더 아래에 test.jsp파일을 생성해서 원하는 내용으로 작성해두면 MyController 실행후 test.jsp가 실행되어 확인이 편리할 것이다.
아래와 같이 실행해서 컨트롤러 클래스가 정상적으로 작동하는지 확인해 보자.
http://localhost:8081/TestTest/mytest.do
2019년 5월 7일 화요일
2019년 4월 10일 수요일
유니코드를 한글로 변환하기
파이썬에서 유니코드 형태의 한글을 정상적으로 표시되도록 하는 방법에 대한 것이다.
아래 변수 a에 다음과 같은 형태의 유니코드 값이 있을 때 이것을 정상적으로 한글로 표시되게 할려면 encode() 함수를 이용해서 byte형으로 변환 후 decode() 함수를 이용해서 unicode_escape 처리를 해 주면 된다.
아래에서 #-*- coding:utf-8 -*-는 파이썬에서 한글을 사용하고자 할때 필요한 코드이다.
비록 주석이라 할지라도 이 코드로 지정하지 않으면 한글이 들어간 코드는 컴파일 단계에서 에러를 내뿜는다.
아래 변수 a에 다음과 같은 형태의 유니코드 값이 있을 때 이것을 정상적으로 한글로 표시되게 할려면 encode() 함수를 이용해서 byte형으로 변환 후 decode() 함수를 이용해서 unicode_escape 처리를 해 주면 된다.
아래에서 #-*- coding:utf-8 -*-는 파이썬에서 한글을 사용하고자 할때 필요한 코드이다.
비록 주석이라 할지라도 이 코드로 지정하지 않으면 한글이 들어간 코드는 컴파일 단계에서 에러를 내뿜는다.
#-*- coding:utf-8 -*-
a = "\uc790\uc720 \ub300\ud55c\ubbfc\uad6d \ub9cc\uc138"
#유니코드 문자열을 한글로 변환하기 위해서는 먼저 문자열을 encode 함수를 통해
# bytes 형으로 변환하고, decode 함수를 사용하여 'unicode_escape' 처리를 해 주면
# 한글이 제대로 출력된다.
a = a.encode('utf-8')
a = a.decode('unicode_escape')
print a
a = "\uc790\uc720 \ub300\ud55c\ubbfc\uad6d \ub9cc\uc138"
#유니코드 문자열을 한글로 변환하기 위해서는 먼저 문자열을 encode 함수를 통해
# bytes 형으로 변환하고, decode 함수를 사용하여 'unicode_escape' 처리를 해 주면
# 한글이 제대로 출력된다.
a = a.encode('utf-8')
a = a.decode('unicode_escape')
print a
위 코드의 실행 결과는 아래와 같이 표현된다.
자유 대한민국 만세
2019년 4월 3일 수요일
앱의 Build And Run시에 앱에 등록된 기존의 데이터 특히 AlarmManager 정보의 존재 유무
어떤 앱을 개발중이다. 그 앱에는 AlarmManager를 이용해서 매일 정해진 시각에 알람 통지 + 알람 사운드를 울려준다고 할때
기 등록된 알람 시각 값이 SharedPreferences에 저장이 되어 있다.
그리고 그렇게 등록된대로 정해진 시간에 알람이 울린다.
그런데 개발 중이기 때문에 코드를 수정해 가면서 새롭게 앱을 Build and Run(맥에서 Control-R 혹은 Control-Shift-R) 시키면
기 등록된 알람 데이터(SharedPreferences에 저장된 데이터)는 어떻게 될까?
사라질까? 그대로 남아 있을까?
즉 그렇게 Build And Run을 기키면 기존 등록된 알람 시간에 정상적으로 알람을 울려줄까?
즉 Android 시스템에 등록된 AlarmManager의 등록된 객체(등록된 알람 시간)는 어떻게 될까? 그대로 존재할까 아니면 사라질까?
물론 앱을 폰에서 삭제한 후에 다시 Build and Run을 시키면 당연히 저장되어 있던 알람 데이터는 삭제된다.
이때는 해당 앱과 관계된 모든 데이터는 삭제된다.
그런데 폰에서 앱을 삭제하지 않고 수정된 코드를 테스트 및 확인하기 위해 Build and Run을 시키면 어떻게 될까?
구글의 API Reference 문서에 나와있는지 모르겠으나 내가 테스트해 본 바로는 첫 번째 Build and Run 때에는 기존의 설정 데이터가 그대로 보존되었다.
그러나 이것이 두 번, 세번 반복될때부터는 기존의 데이터들이 사라지게 된다.
정확히 말하면 SharedPreferences에 저장된 데이터는 삭제가 되지 않는다.
다만 Android 시스템에 등록되어 있던 AlarmManager의 등록된 객체가 사라진다는 것이다.
아무튼 결론은 Build and Run은 기존의 데이터 특히 AlarmManager에 대해 보장해 주지 않는다는 점이다.
이렇게 Android 시스템에 등록된 AlarmManager 객체의 존재 여부를 확인할려면 adb 명령을 통해서 확인할 수 있다.
DOS 창(리눅스나 Mac OS의 경우 터미널 창)에서 Android SDK가 설치된 경로의 platform-tools 폴더의 하위 경로로 이동해서(adb.exe가 있는 위치로 이동해서)
스마트폰을 PC와 연결한 후 아래 커맨더로 안드로이드 시스템에 등록된 AlarmManager의 정보를 확인할수 있다.
adb shell dumpsys alarm
그러면 아래와 같은 복잡한 정보가 나온다.
기 등록된 알람 시각 값이 SharedPreferences에 저장이 되어 있다.
그리고 그렇게 등록된대로 정해진 시간에 알람이 울린다.
그런데 개발 중이기 때문에 코드를 수정해 가면서 새롭게 앱을 Build and Run(맥에서 Control-R 혹은 Control-Shift-R) 시키면
기 등록된 알람 데이터(SharedPreferences에 저장된 데이터)는 어떻게 될까?
사라질까? 그대로 남아 있을까?
즉 그렇게 Build And Run을 기키면 기존 등록된 알람 시간에 정상적으로 알람을 울려줄까?
즉 Android 시스템에 등록된 AlarmManager의 등록된 객체(등록된 알람 시간)는 어떻게 될까? 그대로 존재할까 아니면 사라질까?
물론 앱을 폰에서 삭제한 후에 다시 Build and Run을 시키면 당연히 저장되어 있던 알람 데이터는 삭제된다.
이때는 해당 앱과 관계된 모든 데이터는 삭제된다.
그런데 폰에서 앱을 삭제하지 않고 수정된 코드를 테스트 및 확인하기 위해 Build and Run을 시키면 어떻게 될까?
구글의 API Reference 문서에 나와있는지 모르겠으나 내가 테스트해 본 바로는 첫 번째 Build and Run 때에는 기존의 설정 데이터가 그대로 보존되었다.
그러나 이것이 두 번, 세번 반복될때부터는 기존의 데이터들이 사라지게 된다.
정확히 말하면 SharedPreferences에 저장된 데이터는 삭제가 되지 않는다.
다만 Android 시스템에 등록되어 있던 AlarmManager의 등록된 객체가 사라진다는 것이다.
아무튼 결론은 Build and Run은 기존의 데이터 특히 AlarmManager에 대해 보장해 주지 않는다는 점이다.
이렇게 Android 시스템에 등록된 AlarmManager 객체의 존재 여부를 확인할려면 adb 명령을 통해서 확인할 수 있다.
DOS 창(리눅스나 Mac OS의 경우 터미널 창)에서 Android SDK가 설치된 경로의 platform-tools 폴더의 하위 경로로 이동해서(adb.exe가 있는 위치로 이동해서)
스마트폰을 PC와 연결한 후 아래 커맨더로 안드로이드 시스템에 등록된 AlarmManager의 정보를 확인할수 있다.
adb shell dumpsys alarm
그러면 아래와 같은 복잡한 정보가 나온다.
RTC_WAKEUP #0: Alarm{198895e type 0 when 1554422926096 com.sweettracker.smartparcel}
tag=*walarm*:com.sweettracker.smartparcel/.halibut.HalibutSendAlarmReceiver
type=0 whenElapsed=+17h46m43s806ms when=2019-04-05 09:08:46
window=0 repeatInterval=0 count=0 flags=0x5
operation=PendingIntent{481513f: PendingIntentRecord{251a79d com.sweettracker.smartparcel broadcastIntent}}
Batch{c31876b num=13 start=1116619814 end=1118823179 flgs=0xc}:
ELAPSED_WAKEUP #12: Alarm{cdfc404 type 2 when 1116619814 com.google.android.gms}
tag=*walarm*:com.google.android.gms.fido.authenticator.autoenroll.FIDO_KEY_VALIDITY_CHECK_DELAY_COMPLETE
type=2 whenElapsed=+17h50m44s97ms when=+17h50m44s97ms
window=+23h58m48s19ms repeatInterval=0 count=0 flags=0x0
operation=PendingIntent{817dded: PendingIntentRecord{4961bdd com.google.android.gms startService}}
ELAPSED_WAKEUP #11: Alarm{45e5238 type 2 when 1114137316 com.android.vending}
tag=*walarm*:com.google.android.finsky.scheduler.FALLBACK3
type=2 whenElapsed=+17h9m21s599ms when=+17h9m21s599ms
window=+13h29m59s997ms repeatInterval=0 count=0 flags=0x0
operation=PendingIntent{8864211: PendingIntentRecord{16720ff com.android.vending startService}}
RTC_WAKEUP #10: Alarm{e07e04e type 0 when 1554418207741 com.example.exalarm_repeat}
tag=*walarm*:com.example.exalarm_repeat/.AlarmReceiver
type=0 whenElapsed=+16h28m5s451ms when=2019-04-05 07:50:07
window=+12h38m59s998ms repeatInterval=0 count=0 flags=0x4
operation=PendingIntent{a06756f: PendingIntentRecord{1faa808 com.example.exalarm_repeat broadcastIntent}}
RTC_WAKEUP #9: Alarm{a15e422 type 0 when 1554416429513 com.hubizict.orientalhospital}
tag=*walarm*:com.hubizict.orientalhospital/com.com.hubizict.orientalhospital.util.AlarmReceiver
type=0 whenElapsed=+15h58m27s223ms when=2019-04-05 07:20:29
window=+18h0m0s0ms repeatInterval=86400000 count=0 flags=0x0
operation=PendingIntent{fa09fd1: PendingIntentRecord{82563d9 com.hubizict.orientalhospital broadcastIntent}}
RTC_WAKEUP #8: Alarm{b20aeb3 type 0 when 1554414158867 com.hubizict.orientalhospital}
tag=*walarm*:com.hubizict.orientalhospital/com.com.hubizict.orientalhospital.util.AlarmReceiver
type=0 whenElapsed=+15h20m36s577ms when=2019-04-05 06:42:38
window=+18h0m0s0ms repeatInterval=86400000 count=0 flags=0x0
operation=PendingIntent{2767809: PendingIntentRecord{3bbc438 com.hubizict.orientalhospital broadcastIntent}}
ELAPSED_WAKEUP #7: Alarm{3717f76 type 2 when 1092537187 com.android.vending}
tag=*walarm*:com.google.android.finsky.scheduler.FALLBACK2
type=2 whenElapsed=+11h9m21s470ms when=+11h9m21s470ms
window=+8h59m59s911ms repeatInterval=0 count=0 flags=0x0
operation=PendingIntent{76d6977: PendingIntentRecord{c06475d com.android.vending startService}}
ELAPSED #6: Alarm{5883bd1 type 3 when 1086423185 com.google.android.gms}
tag=*alarm*:com.google.android.gms.common.download.START
type=3 whenElapsed=+9h27m27s468ms when=+9h27m27s468ms
window=+8h59m59s994ms repeatInterval=0 count=0 flags=0x0
operation=PendingIntent{1e15636: PendingIntentRecord{1f064f1 com.google.android.gms startService}}
RTC #5: Alarm{5298f9c type 1 when 1554392921828 com.sec.android.app.sns3}
tag=*alarm*:com.sec.android.app.sns.profile.ACTION_CHECK_OLD_DATA
type=1 whenElapsed=+9h26m39s538ms when=2019-04-05 00:48:41
window=+18h0m0s0ms repeatInterval=86400000 count=0 flags=0x0
operation=PendingIntent{5b099c3: PendingIntentRecord{8cfdc97 com.sec.android.app.sns3 broadcastIntent}}
ELAPSED_WAKEUP #4: Alarm{b1bdda5 type 2 when 1086297010 com.google.android.gms}
tag=*walarm*:com.google.android.gms.auth.authzen.CHECK_REGISTRATION
type=2 whenElapsed=+9h25m21s293ms when=+9h25m21s293ms
window=+15h38m54s702ms repeatInterval=0 count=0 flags=0x0
operation=PendingIntent{b03d57a: PendingIntentRecord{4cedd0f com.google.android.gms broadcastIntent}}
이상의 정보에서 위의 색상으로 표시된 내용을 보면 패키지가 com.example.exalarm_repeat로 되어 있는 앱에 의해서
RTC_WAKEUP형태로 등록되어 있고 알람 시각은 when=2019-04-05 07:50:07으로 등록되어 있음을 확인하게 된다.
그런데 앱을 Build And Run을 반복하게 되면 안드로이드 시스템에 등록된 AlarmManager 객체(정보)가 사라진다는 것이다.
그러나 SharedPreferences에 저장된 값은 그대로 존속한다. 따라서 이로 인해 등록된 정보가 SharedPreferences에 있기 때문에 정해진 시간에 알람이 울리리라 생각하지만 실상은 이상과 같은 일들이 내부에서 벌어진 것이다.
tag=*walarm*:com.sweettracker.smartparcel/.halibut.HalibutSendAlarmReceiver
type=0 whenElapsed=+17h46m43s806ms when=2019-04-05 09:08:46
window=0 repeatInterval=0 count=0 flags=0x5
operation=PendingIntent{481513f: PendingIntentRecord{251a79d com.sweettracker.smartparcel broadcastIntent}}
Batch{c31876b num=13 start=1116619814 end=1118823179 flgs=0xc}:
ELAPSED_WAKEUP #12: Alarm{cdfc404 type 2 when 1116619814 com.google.android.gms}
tag=*walarm*:com.google.android.gms.fido.authenticator.autoenroll.FIDO_KEY_VALIDITY_CHECK_DELAY_COMPLETE
type=2 whenElapsed=+17h50m44s97ms when=+17h50m44s97ms
window=+23h58m48s19ms repeatInterval=0 count=0 flags=0x0
operation=PendingIntent{817dded: PendingIntentRecord{4961bdd com.google.android.gms startService}}
ELAPSED_WAKEUP #11: Alarm{45e5238 type 2 when 1114137316 com.android.vending}
tag=*walarm*:com.google.android.finsky.scheduler.FALLBACK3
type=2 whenElapsed=+17h9m21s599ms when=+17h9m21s599ms
window=+13h29m59s997ms repeatInterval=0 count=0 flags=0x0
operation=PendingIntent{8864211: PendingIntentRecord{16720ff com.android.vending startService}}
RTC_WAKEUP #10: Alarm{e07e04e type 0 when 1554418207741 com.example.exalarm_repeat}
tag=*walarm*:com.example.exalarm_repeat/.AlarmReceiver
type=0 whenElapsed=+16h28m5s451ms when=2019-04-05 07:50:07
window=+12h38m59s998ms repeatInterval=0 count=0 flags=0x4
operation=PendingIntent{a06756f: PendingIntentRecord{1faa808 com.example.exalarm_repeat broadcastIntent}}
RTC_WAKEUP #9: Alarm{a15e422 type 0 when 1554416429513 com.hubizict.orientalhospital}
tag=*walarm*:com.hubizict.orientalhospital/com.com.hubizict.orientalhospital.util.AlarmReceiver
type=0 whenElapsed=+15h58m27s223ms when=2019-04-05 07:20:29
window=+18h0m0s0ms repeatInterval=86400000 count=0 flags=0x0
operation=PendingIntent{fa09fd1: PendingIntentRecord{82563d9 com.hubizict.orientalhospital broadcastIntent}}
RTC_WAKEUP #8: Alarm{b20aeb3 type 0 when 1554414158867 com.hubizict.orientalhospital}
tag=*walarm*:com.hubizict.orientalhospital/com.com.hubizict.orientalhospital.util.AlarmReceiver
type=0 whenElapsed=+15h20m36s577ms when=2019-04-05 06:42:38
window=+18h0m0s0ms repeatInterval=86400000 count=0 flags=0x0
operation=PendingIntent{2767809: PendingIntentRecord{3bbc438 com.hubizict.orientalhospital broadcastIntent}}
ELAPSED_WAKEUP #7: Alarm{3717f76 type 2 when 1092537187 com.android.vending}
tag=*walarm*:com.google.android.finsky.scheduler.FALLBACK2
type=2 whenElapsed=+11h9m21s470ms when=+11h9m21s470ms
window=+8h59m59s911ms repeatInterval=0 count=0 flags=0x0
operation=PendingIntent{76d6977: PendingIntentRecord{c06475d com.android.vending startService}}
ELAPSED #6: Alarm{5883bd1 type 3 when 1086423185 com.google.android.gms}
tag=*alarm*:com.google.android.gms.common.download.START
type=3 whenElapsed=+9h27m27s468ms when=+9h27m27s468ms
window=+8h59m59s994ms repeatInterval=0 count=0 flags=0x0
operation=PendingIntent{1e15636: PendingIntentRecord{1f064f1 com.google.android.gms startService}}
RTC #5: Alarm{5298f9c type 1 when 1554392921828 com.sec.android.app.sns3}
tag=*alarm*:com.sec.android.app.sns.profile.ACTION_CHECK_OLD_DATA
type=1 whenElapsed=+9h26m39s538ms when=2019-04-05 00:48:41
window=+18h0m0s0ms repeatInterval=86400000 count=0 flags=0x0
operation=PendingIntent{5b099c3: PendingIntentRecord{8cfdc97 com.sec.android.app.sns3 broadcastIntent}}
ELAPSED_WAKEUP #4: Alarm{b1bdda5 type 2 when 1086297010 com.google.android.gms}
tag=*walarm*:com.google.android.gms.auth.authzen.CHECK_REGISTRATION
type=2 whenElapsed=+9h25m21s293ms when=+9h25m21s293ms
window=+15h38m54s702ms repeatInterval=0 count=0 flags=0x0
operation=PendingIntent{b03d57a: PendingIntentRecord{4cedd0f com.google.android.gms broadcastIntent}}
이상의 정보에서 위의 색상으로 표시된 내용을 보면 패키지가 com.example.exalarm_repeat로 되어 있는 앱에 의해서
RTC_WAKEUP형태로 등록되어 있고 알람 시각은 when=2019-04-05 07:50:07으로 등록되어 있음을 확인하게 된다.
그런데 앱을 Build And Run을 반복하게 되면 안드로이드 시스템에 등록된 AlarmManager 객체(정보)가 사라진다는 것이다.
그러나 SharedPreferences에 저장된 값은 그대로 존속한다. 따라서 이로 인해 등록된 정보가 SharedPreferences에 있기 때문에 정해진 시간에 알람이 울리리라 생각하지만 실상은 이상과 같은 일들이 내부에서 벌어진 것이다.
2019년 4월 2일 화요일
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/message/HeaderGroup 에러 해법
- 안드로이드 SDK가 Pie로 업그레이드 된 폰에서 다음과 같은 에러가 발생할 경우 대처 법
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/message/HeaderGroup
(1) 앱 수준의 build.gradle의 targetSdkVersion을 28로 된 것을 27로 변경해 준다. 28에서 발생하는 문제이다. Api Level 28은 Pie(Android version 9)이고 27은 Oreo(Android version 8.1)이다.
(2) Manifest.xml의 <application> 속성 아래에 다음 코드를 추가한다.
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<uses-library android:name=“org.apache.http.legacy” android:required=“false” />
…. />
구글의 설명을 들어보면 play-service map을 사용할때 발생하는 문제로 설명되어 있다.
If you are using com.google.android.gms:play-services-maps:16.0.0 or below and your app is targeting API level 28 (Android 9.0) or above, you must include the following declaration within the <application> element ofAndroidManifest.xml.
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
android:name="org.apache.http.legacy"
android:required="false" />
This is handled for you if you are using com.google.android.gms:play-services-maps:16.1.0 and is not necessary if your app is targeting a lower API level.
2018년 10월 26일 금요일
Instantiation of bean failed; Failed to instantiate [......]: Specified class is an interface 에러 문제
Spring(혹은 전자정부프레임워크)에서 maven build가 정상적으로 수행된 후에 『Run As - Java Application』으로 해당 클래스를 실행했을 때 다음과 같은 에러가 발생했다면 무엇이 문제라는 것일까?
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageBean' defined in class path resource [context-hello.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.joe.MessageBean]: Specified class is an interface
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1105)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1050)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.joe.HelloApp.main(HelloApp.java:10)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.joe.MessageBean]: Specified class is an interface
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:68)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1098)
... 13 more
위의 에러메시지에서 몇 가지 단서들을 확인할수 있는데
-. context-hello.xml에 있는 messageBean이라는 이름의 bean 객체를 생성하지 못했다는 것이고
Error creating bean with name 'messageBean' defined in class path resource [context-hello.xml]
-. bean을 생성하기 위해 지정된 클래스가 interface이기 때문에 bean(객체)를 생성할수 없다
Failed to instantiate [com.joe.MessageBean]: Specified class is an interface
참고로 context-hello.xml 파일의 내용은 다음과 같다.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 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.2.xsd">
<bean name="messageBean" class="com.joe.MessageBean" />
</beans>
그러면 bean을 생성할 대상이 되는 클래스인 com.joe.MessageBean를 보면 다음과 같다.
package com.joe;
public interface MessageBean {
public void sayHello(String name);
}
따라서 결국은 문제가 된 것은 context-hello.xml에서 bean 생성 할 대상으로 지정한 클래스가 interface여서 발생한 에러였다. Java는 근본적으로 interface를 막바로 객체(bean) 생성할수가 없다. 만일 객체를 생성할수 있다고 한들 그 객체가 행할수 있는 기능(메소드) 자체가 정의되어 있지 않기 때문에, 위에서 보듯이 sayHello()라는 메소드가 무엇을 행할지 내용이 없다. 이것이 interface이다.
따라서 interface는 객체를 막바로 생성할수가 없고 생성할수 있다고 해도 그 객체(bean)이 아무런 동작도 할것이 없는것이다.
따라서 interface는 객체를 막바로 생성할수가 없고 생성할수 있다고 해도 그 객체(bean)이 아무런 동작도 할것이 없는것이다.
따라서 interface를 구현한(implements) 클래스를 객체로(bean)으로 생성하도록 context-hello.xml의 내용을 변경해 주어야 한다.
여기서 MessageBean 인터페이스를 구현한 하위 클래스는 다음과 같다.
package com.joe;
public class MessageBeanEng implements MessageBean {
@Override public void sayHello(String name){
System.out.println("Hello, "+name);
}
}
따라서 context-hello.xml의 내용을 바꾸어 주어야하는데 interface인 MessageBean을 그 구현 클래스인 MessageBeanEng로 변경해 주어야 하는 것이다.
<bean name="messageBean" class="com.joe.MessageBean" />
를 아래와 같이 바꾸어 주어야 한다.
<bean name="messageBean" class="com.joe.MessageBeanEng" />
2018년 10월 18일 목요일
Spring(혹은 전자정부프레임워크)에서 DI(Dependency Injection 의존성 주입)에 대한 개념과 예제 코드
Spring(혹은 전자정부프레임워크)에서 자주 사용되는 개념인 DI(Dependency Injection)에 대해서 간단한 예제를 통해 살펴보고자 한다.
DI란 '의존성 주입'이라고 번역이 되는데 표현 자체가 거창해서 그렇지 사실은 그동안 프로그래밍에서 사용되어 오던 것이다.
예를들어 업로드 파일을 서버에 저장하는 SaveFile이라는 클래스가 있을 때 저장되는 파일 이름을 모두 대문자로 변환해서 저장하는 ToUpper라는 클래스를 SaveFile에서 사용한다고 하면 SaveFile은 ToUpper 클래스에 의존되어 있다고 표현한다.
class SaveFile
{
private File file;
private ToUpper upper;
private void saveFile() {
//여기서 upper객체를 사용해서 파일이름을 대문자로 변환후 저장하는 코드
}
.......
}
이럴 경우 ToUpper 클래스를 SaveFile 클래스 내부에서 new로 생성해서 사용할수도 있지만 ToUpper 클래스를 외부에서 주입해서(이걸 DI라고 한다) 사용할수 있을 것이다.
가장 보편적인 방법은 SaveFile의 생성자에서 매개인자(파라미터)로 ToUpper 클래스의 객체를 받아서 사용하는 형태가 있을 것이다.
class SaveFile
{
private File file;
private ToUpper upper;
public SaveFile(ToUpper upper){ //생성자를 통해 의존성 주입(DI)하는 방식
this.upper = upper;
}
private void saveFile() {
//여기서 upper객체를 사용해서 파일이름을 대문자로 변환후 저장하는 코드
}
.......
}
그런데 이 방식외에 Spring 컨테이너의 도움을 받아서 XML 설정 파일의 property 태그를 이용하는 방법도 있다.
이때 사용되는 것은 setter 메소드이다.
class SaveFile
{
private File file;
private ToUpper upper;
//setter만드는 규약에 맞게 setter 메소드를 만들어 두면 Spring 컨테이너가
//XML 설정 파일의 property 태그를 이용해서 ToUpper 클래스의 객체를
//아래 메소드의 파라미터인 mUpper에 주입(DI)해 준다.
//따라서 ToUpper 클래스의 객체를 new로 생성하지 않아도 정상적으로 사용할수 있는것이다.
//setter를 만드는 규칙은 XML 설정 파일의 property name가 upper로 되어 있는 것을 근거로
//upper의 첫 글자를 대문자로(U) 바꾼 후 앞에 set을 추가한 형태인 setUpper로 만들면
//Spring 컨테이너가 알아서 이 setter를 찾아서 해당 property의 ref가 지정한 bean을
//mUpper에 주입해 준다. 이것이 프라퍼티를 이용한 DI 방식이다.
public void setUpper(ToUpper mUpper) {
this.upper = mUpper;
}
private void saveFile() {
//여기서 upper객체를 사용해서 파일이름을 대문자로 변환후 저장하는 코드
}
.......
}
※ ToUpper 클래스의 내용은 생략(해당 클래스가 잘 만들어져 있다고 가정...)
아래는 XML 설정파일의 정보이다. 파일 이름이 MyBean.xml이라고 가정한다.
<?xml version = "1.0" encoding = "UTF-8"?>
<beans xmlns = "http://www.springframework.org/schema/beans"
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.0.xsd">
<!-- SaveFile 클래스를 임의 클래스에서 객체로 사용하도록 bean 정보 설정 -->
<bean id = "mySaveFile" class = "com.joe.SaveFile">
<!-- SaveFile 클래스의 setUpper()에게로 ref가 지정하는 bean(객체)를 Spring 컨테이너가 주입해준다
즉 SaveFile 클래스에서 setUpper()의 매개인자로 ref가 지정하는 bean을 주입해 준다.
즉 setUpper(myUpper)식이 되는 것이다.
-->
<property name = "upper" ref = "myUpper"/>
</bean>
<!-- SaveFile 클래스가 사용하게 될 ToUpper 클래스에 대한 bean -->
<bean id = "myUpper" class = "com.joe.ToUpper"></bean>
</beans>
이제 사용하는 방법은 다음과 같다.
package com.joe;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MainApp {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("MyBean.xml");
SaveFile sf = (SaveFile) context.getBean("mySaveFile");
sf.saveFile();
}
}
2018년 8월 30일 목요일
HTML의 col 태그에 대해서
HTML의 <col> 태그에 대해서
<col> 태그는 테이블에서 column(열)의 속성을 지정하는 역할을 하는 태그이다.
<col> 태그는 테이블의 column 전체에 특정한 속성(예를들어 특정 색상으로 표시되게)을 적용하는데 유용하다.
다음과 같은 코드가 있다고 할때
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<table>
<colgroup>
<col style="background-color:red">
<col style="background-color:yellow">
<col style="background-color:#ababab">
</colgroup>
<tr>
<th>이름</th>
<th>나이</th>
<th>전화번호</th>
</tr>
<tr>
<td>홍길동</td>
<td>25</td>
<td>010-1234-4567</td>
</tr>
<tr>
<td>고길동</td>
<td>45</td>
<td>010-7777-8888</td>
</tr>
</table>
</body>
</html>
이 경우 테이블은 2행 3열의 테이블을 이룰것인데 colgroup 안에서 첫 번째 column 전체를 red로, 두 번째 column 전체를 yellow로 그리고 세 번째 column 전체의 색상을 짙은 회색(#ababab의 색상이 짙은 회색임)으로 column의 속성을 지정하는 경우가 되겠다.
만일 col 태그의 내용을 다음과 같이하면
<colgroup>
<col span="2" style="background-color:red">
<col style="background-color:#ababab">
</colgroup>
이 경우는 다음과 같이 첫 번째, 두 번째 column 전체가 red로 설정이 된다. 왜냐하면 span 속성에 의해 첫번째와 두번째 column을 합쳐서 적용하도록 했기 때문이다.
만일 col 태그의 내용을 다음과 같이하면
<colgroup>
<col style="background-color:red">
<col span="2" style="background-color:yellow">
</colgroup>
이 경우는 다음과 같이 첫 번째 column은 red, 두 번째, 세 번째 column은 yellow로 적용이 될 것이다.
2018년 8월 22일 수요일
크롬 웹 브라우저의 개발자 도구 - 검사 (특정 영역의 html 요소 확인하기)

웹 애플리케이션 개발시 크롬 웹 브라우저의 개발자 도구(F12, 혹은 Ctrl-Shift-I)를 적절히 활용하면 html 코드의 복잡한 숲속에서 좀 더 스마트하게 돌아다닐수가 있게 된다.
오늘 포스팅에서는 개발자 도구 중에서 웹 페이지의 복잡한 구조 중에서 특정 영역에 대한 html 요소를 한번에 쉽게 찾아서 확인하는 방법에 대한 글이다.
보통은 디자이너나 웹 프블리셔가 디자인이 적용된 html, css 파일을 던져 주면 그것을 가지고 개발자가 기능을 구현하게 될텐데 구성이 복잡한 웹 페이지의 경우 특정 영역에 대한 html 구성이 어떻게 되었는지를 확인할려면 html 태그 숲 속을 헤매는 경우가 있다.
이러한 작업을 한번에 해결해 주는 기능이 크롬 웹 브라우저의 개발자 도구가 제공하고 있다.
아래와 같은 웹 페이지가 있다고 할 경우(이해를 돕기 위해서 그냥 단순한 경우를 예로 살펴보기로...) 빨간색 영역에 대한 html 요소를 확인하고자하면
(저 영역이 사실은 게시글 작성자 닉네임을 적는 공간인데 input 태그로 되어 있는 영역이다. 이미지가 좀 희미...;;)
(저 영역이 사실은 게시글 작성자 닉네임을 적는 공간인데 input 태그로 되어 있는 영역이다. 이미지가 좀 희미...;;)
-. F12로 개발자 도구 창이 활성화 되도록 한 후에 상단의 "Elements" 탭을 클릭
-. 웹 페이지에서 해당 영역을 마우스로 클릭한 후 마우스 우측을 클릭
-. 팝업 메뉴 중에서 "검사(N)"을 클릭하면
-. 우측 개발자 창에서 해당 영역에 대한 html 요소에 대한 정보가 한번에 보여진다.
피드 구독하기:
글 (Atom)




