[Android] Android 로깅 시 isLoggable() 메서드 사용

아래와 같이 isLoggable 이라는 메서드를 사용하여 원하는 로그를 찍고 싶을 경우 system property 값을 원하는 로그 레벨로 변경해 주거나 local.prop 파일을 생성하여 /data/local.prop 으로 위치시켜야 한다. public static void LOGD(final String tag, String message, Throwable cause) {         if (LOGGING_ENABLED){             if (Log. isLoggable (tag, Log.DEBUG)) {                 Log.d(tag, message, cause);             }         }   } system property 값을 변경해 주는 방법은 다음과 같다. adb shell setprop log.tag.<tag> <log level> myLog 라는 tag 를 debug 레벨에서 찍고 싶다면, console 창에서 아래와 같이 써주면 된다. adb shell setprop lgo.tag. myLog DEBUG * 공식사이트에 나와있는 isLoggable 메서드 관련 설명 public static boolean  isLoggable   ( String  tag, int level) Added in  API level 1 Checks to see whether or not a log for the specified tag is loggable at the specified level. The default level of any tag ...

[Spring] @PropertySource and Environment 사용시 Property 값이 null 로 들어오는 경우

Spring에서 Property 값을 아래와 같이 가져올 수 있다. @Configuration @PropertySource("classpath:myProperties.properties") public class MyConfiguration { @Autowired Environment environment; public DataSource getDataSource(){     dataSource.setDriverClassName(environment.get("jdbc.driverClassName"));     return dataSource; } } 하지만, Autowiring이 늦게 발생하는 경우 environment 에는 값이 없는 상태로 MyConfiguration 의 getDataSource() 메서드가 먼저 실행된다. 일종의 트릭이지만, org.springframwork.context.EnvironmentAware 를 implement 하여 해결할 수 있다. @Configuration @PropertySource("classpath:myProperties.properties") public class MyConfiguration implements EnvironmentAware {  private Environment environment;  @Override  public void setEnvironment(final Environment environment) {   this.environment = environment;  }  public void myMethod() {   final String myPropertyValue = environment.getProperty("myProperty");   // ...   } } refs : http://sta...

[SVN] commit fails with “Authorization failed” error

SVN 저장소를 새로 만들어서 소스코드를 업로드하는 중에 다음과 같은 에러가 발생하였다. SVN commit fails with “Authorization failed” error SVN 생성 폴더의 conf/svnserve 에 있는 디렉토리 접근 권한을 설정해 주지 않아서 발생한 문제였다. auth-access = write 설정을 추가하여 해결 하였다.

[Android] Android Local Unit Tests 환경 구성

이미지
Android 앱 개발 시 테스트하는 방법은 두가지가 있다. Instrumented Unit Tests Local Unit Tests 그중 하나인 Local Unit Tests 환경설정을 정리해 본다.  Local Unit Test 는 테스트하고자 하는 코드가 Android System 에 크게 의존적이지 않을 때 사용한다. 환경설정 폴더 생성 : 테스트 코드는 src/test/java 폴더에 위치해야 한다. 프로젝트 구조 build.gradle - dependancies 추가 testCompile  'junit:junit:4.12' testCompile  'org.mockito:mockito-core:1.10.19' testCompile  'org.hamcrest:hamcrest-library:1.1' 테스트 코드 작성 테스트 코드 구조 테스트 실행  안드로디으 스튜디오에 있는  Build Variants 창 클릭  Test Artifact 를 Unit Tests 로 변경   Run 메뉴에서 Unit Test 를 실행 Unit Tests 가 활성화 된 화면 ref : http://developer.android.com/intl/ko/training/testing/unit-testing/local-unit-tests.html

[UnitTest] 에서 andDo(print()) 사용 시 java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.isAsyncStarted() 에러 조치

문제 : 서블릿 3.0 을 사용하고 있음에도 버전 충돌이 생겨 테스트가 진행이 되지 않음 원인 : servlet 버전이 맞지 않았을 때 발생. spring 4.0 의 spring-test 에서는 servlet 3.0 스펙을 요구함 상태 : servlet-api-3.0 버전을 사용하고, web.xml 에도 3.0사용을 명시를 하였으나, HttpServletRequest.isAsyncStarted() 메서드가 없다는 에러가 계속 발생함. 조치 1 :  Maven reference 에 servlet-2.x 를 사용하고 있는지 확인 누가 사용하는지는 모르지만 servlet-api-2.5.jar 가 들어가 있는 것을 확인 조치 2 :  mvn dependency:tree -Dverbose -Dincludes=javax.servlet 명령어로 메이븐   의존 tree 검색 junit-runner 에서 servelt-api-2.5를 사용하고 잇는 것을 발견.  해당 버전 업데이트 하여 해결

[JDBC] 쿼리 후에 ResultSet 에 데이터가 있는지 확인하는 방법

외부 DB와 연동하는 코드에서 ResultSet에 데이터가 있는지 여부 아래와 같이 확인하였다. ResultSet rs = null; if(rs.next()){     rs.previous()     //조회 된 데이터를 DB에 저장 } MySQL에서 데이터를 불러올 때는 문제가 없었지만 MSSQL에서 커서는 전방향 전용 결과 집합에 부적합한 작업이 수행되었습니다.  라는   에러가 발생하였다. 이는 ResultSet 기본설정이 TYPE_FORWARD_ONLY 로 되어있기 때문이다. 아래와 같이 상수 두개를 선언해 주어 에러가 발생하지 않도록 조치하였다. 조치 방법은 2가지 이다. 1. 기본설정 변경 PreparedStatement pstmt = dbConnFactory.getConnection().prepareStatement(connectorManager.getCollectorConfig().getQuery(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); 2. 메서드 사용 rs.isBeforeFirst();  조회 된 데이터가 없으면 false 를 반환한다.

[Spring] Springfox-swagger 적용하여 API문서 자동 생성 하기(asciidoc, markdown)

이미지
pom.xml 에 dependency 및 plugin 추가         <dependency>             <groupId>io.springfox</groupId>             <artifactId>springfox-swagger2</artifactId>             <version>2.3.0</version>             <scope>test</scope>         </dependency>         <dependency>             <groupId>io.springfox</groupId>             <artifactId>springfox-staticdocs</artifactId>             <version>2.3.0</version>             <scope>test</scope>         </dependency>         <dependency>           ...