반응형

myapplication 이라는 이름을 가지고 있고 sample 이라는 profile을 설정했을경우 우선순위는 다음과 같다.


1. myapplication-sample.yml

2. myapplication.yml

3. myapplication.properties



728x90
반응형

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

[Spring]Controller Test 하기  (0) 2017.06.12
[Spring]Jasypt 를 이용한 properties 암호화  (6) 2017.04.25
spring Cache  (0) 2015.12.05
Spring propagation  (0) 2015.12.01
[JPA]Persistence Context  (0) 2015.08.25
반응형

@Cacheable

캐시할 메서드를 지정한다. 

위 어노테이션을 사용한 메서드는 결과를 캐시에 저장하기 때문에 뒤이은 호출에서는 실제로 메서드를 실행하지 않고 캐시에 저장된 값을 반환한다.


@CachePut

메서드 실행에 영향을 주지 않고 캐시를 갱신해야 하는 경우.

메서드를 항상 실행하고 그 결과를 캐시에 보관 한다.


@CacheEvict

캐시에 데이터를 제거하는 트리거로 동작하는 메서드 이다.


728x90
반응형

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

[Spring]Jasypt 를 이용한 properties 암호화  (6) 2017.04.25
[SpringCloud]Spring Config..  (0) 2016.01.26
Spring propagation  (0) 2015.12.01
[JPA]Persistence Context  (0) 2015.08.25
[JPA]Entity 생명주기  (0) 2015.08.12
반응형

MANDATORY

Support a current transaction, throw an exception if none exists.

시작된 트랜잭션이 있으면 support, 없으면 예외 발생


NESTED

Execute within a nested transaction if a current transaction exists, behave like PROPAGATION_REQUIRED else.

시작된 트랜잭션이 있으면 중첩해서 트랜잭션을 실행한다. 


NEVER

Execute non-transactionally, throw an exception if a transaction exists.

트랜잭션이 있으면 예외 발생


NOT_SUPPORTED

Execute non-transactionally, suspend the current transaction if one exists.

시작된 트랜잭션이 있으면 보류한 후 트랜잭션 없이 진행한다.


REQUIRED

Support a current transaction, create a new one if none exists.

시작된 트랜잭션이 있으면 support, 없으면 새로운 트랜잭션을 생성한다.


REQUIRES_NEW

Create a new transaction, and suspend the current transaction if one exists.

이미 시작된 트랜잭션이 있으면 보류하고 새로운 트랜잭션을 생성해서 시작한다.


SUPPORTS

Support a current transaction, execute non-transactionally if none exists.

시작된 트랜잭션이 있으면 support, 없으면 없이 진행한다. 

728x90
반응형

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

[SpringCloud]Spring Config..  (0) 2016.01.26
spring Cache  (0) 2015.12.05
[JPA]Persistence Context  (0) 2015.08.25
[JPA]Entity 생명주기  (0) 2015.08.12
Mybatis 동적쿼리 사용시 NuberFormatException:For input String 해결방법  (0) 2014.10.30
반응형

Persistence Context 특징

- 1차 캐시

- 동일성 보장

- 트랜잭션을 지원하는 쓰기 지연 (transaction write-behind)

- 변경감지(dirty checking)

- 지연로딩


조회

- 조회시에 1차캐시에서 식별자 값으로 entity 조회. 없으면 DB에서 조회


등록

- persist 를 실행하면 1차 캐시에 저장 되고 transaction writer-behind에 쿼리를 저장해둔다.

- commit 시점에 transaction writer-behind에 있는 쿼리를 실행함.


수정 

- 1차 캐시에 Entity가 저장될 시점에 최초상태의 스냅샷을 같이 저장한다. 

- transaction writer-behind 에서 flush 시점에 스냅샷과 entity를 비교해서 변경된 entity를 찾는다.

728x90
반응형

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

spring Cache  (0) 2015.12.05
Spring propagation  (0) 2015.12.01
[JPA]Entity 생명주기  (0) 2015.08.12
Mybatis 동적쿼리 사용시 NuberFormatException:For input String 해결방법  (0) 2014.10.30
util.Date vs sql.Date 차이  (0) 2014.07.01
반응형

1. new/transient : persistence context와 무관

2. managed : persistence context에 저장된 상태

3. detached : persistence context에 저장되었다가 분리된 상태

4. removed : 삭제된 상태


728x90
반응형
반응형

Mybatis에서 동적 쿼리 사용시 아래와 같이 비교구문을 작성하게 되면 NuberFormatException이 발생한다.

<when test = 'param !=null and param != "Y"'>


이유는 'Y'를 문자열이 아닌 문자(Char)형태로 인식해서 숫자로 인식하기 때문이다. -_-;


해결방법은 아래 처럼 표기해주면 된다.


1. <when test = 'param != "Y" and param !=null'> 쌍따옴표와 홑따옴표 위치 변경

2. <when test = "param != &quot;Y&quot; and param !=null"> 쌍따옴표를 HTML 코드로 변경

3. <when test = "param != 'Y'.toString() and param !=null"> toString() 함수를 사용해서 String형으로 변환

728x90
반응형

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

[JPA]Persistence Context  (0) 2015.08.25
[JPA]Entity 생명주기  (0) 2015.08.12
util.Date vs sql.Date 차이  (0) 2014.07.01
JSP 용량초과? 65535 bytes limit  (0) 2013.11.21
Reflection 활용한 값 비교  (0) 2013.11.13
반응형

쓰다보면 별 생각없이 사용했던 Date 클래스.

심지어 util.Date 인지 sql.Date인지도 생각도 안하고 썼는데.. (있는지도 잘 몰랐네 -_-)

그런데 이런 차이점이 있었다..


일단 sql 패키지의 Date 클래스는 java.util.Date 클래스를 상속 받는다. 

그런데.. 문제는 이게 값을 가져올때이다.

오버라이딩한 toString을 찾아보면 


  1. public String toString () {
  2.         int year = super.getYear() + 1900;
  3.         int month = super.getMonth() + 1;
  4.         int day = super.getDate();
  5.         char buf[] = "2000-00-00".toCharArray();
  6.         buf[0] = Character.forDigit(year/1000,10);
  7.         buf[1] = Character.forDigit((year/100)%10,10);
  8.         buf[2] = Character.forDigit((year/10)%10,10);
  9.         buf[3] = Character.forDigit(year%10,10);
  10.         buf[5] = Character.forDigit(month/10,10);
  11.         buf[6] = Character.forDigit(month%10,10);
  12.         buf[8] = Character.forDigit(day/10,10);
  13.         buf[9] = Character.forDigit(day%10,10);
  14.         return new String(buf);
  15.     }


보면. 시/분/초 에 대한 내용이 없다. -_-;

따라서 시/분/초까지 정보를 가져오기 위해서는 java.sql.Date가 아닌 java.util.Date를 사용해야한다.


728x90
반응형
반응형

개발을 하다가 갑자기 특정 페이지에 들어가는데 이클립스 로그창에 이런 메세지가 나오더니 페이지 에러가 났다. -_-;

The code of method _jspService(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) is exceeding the 65535 bytes limit

구글링을 해보니 JVM의 Method Size 는 64K로 제한이 된다고 글들이 써있었다.

일단 해결 방법은 서버에 있는 web.xml에 아래와 같이 설정해주면 된다.   

  1. <servlet>
  2.         <servlet-name>jsp</servlet-name>
  3.         <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
  4.         <init-param>
  5.             <param-name>mappedfile</param-name>
  6.             <param-value>false</param-value>
  7.         </init-param>
  8. </servlet>

JVM spec : Limitations of the Java Virtual Machine

위 링크로 들어가보면 어떤것들을 포함해서 64K로 제한되어있는지 설명이 되어있다.. 물론 영어로.



728x90
반응형
반응형

가끔 DB에 입력할 값하고 기존에 있던 값하고 비교해야 할 상황이 생긴다.

그럴때마다 객체에 있는 수많은 getter 메소드를 소스 코드에 써줘야 한다면 코드가 참 지저분할것 같다.

그래서 사용한 방법이 Reflection 이다.

Class에 있는 정보를 읽어와서 실제로 메소드까지 실행 가능하니.. 라인수를 확 줄일 수 있다. ^^

  1. import java.lang.reflect.Method;
  2. public class ReflectionTest {
  3.     public static void main(String[] args) throws Exception {
  4.         // DB에 입력하려는 DATA
  5.         TestVO test = new TestVO();
  6.         test.setId("test");
  7.         test.setName("kim");
  8.         test.setAddr("seoul");
  9.         test.setHobby("game");
  10.        
  11.         printModifyValue(test);
  12.     }
  13.  
  14.     private static void printModifyValue(TestVO test) throws Exception{
  15.         // 값을 비교할 객체에 있는 METHOD를 가져옴
  16.         Method method[] = test.getClass().getDeclaredMethods();
  17.        
  18.         // DB에 현재 존재하는 DATA(DB 연결시에는 DB에서 DATA를 가져오면 됨)
  19.         TestVO testFromDB = new TestVO();
  20.         testFromDB.setId("testDB");
  21.         testFromDB.setName("kim");
  22.         testFromDB.setAddr("Pusan");
  23.         testFromDB.setHobby("music");
  24.        
  25.         // reflection을 이용한 get method  실행
  26.                 for (int i=0; i < method.length; i++){
  27.             String methodName = method[i].getName();
  28.             if (methodName.indexOf("get") != -1){
  29.                 Object inputValue = method[i].invoke(test, null);
  30.                 Object dbValue = method[i].invoke(testFromDB, null);
  31.                
  32.                 // inputValue 가 null, "" 일경우
  33.                 // dbValue 가 null 인데 inputValue 가 "" 인 경우
  34.                 // dbValue 가 "" 안데 inputValue 가 null 인 경우
  35.                 // inputValue 와 dbValue 가 같을 경우
  36.                 if (inputValue == null || "".equals(inputValue) ||
  37.                     dbValue == null && "".equals(inputValue) ||
  38.                     "".equals(dbValue) && inputValue == null ||
  39.                     dbValue.equals(inputValue)){
  40.                     continue;
  41.                 }else if (!dbValue.equals(inputValue)){
  42.                     // 한쪽만 NULL 이거나 값이 서로 같지 않으면 컬럼 값이 변경된 것으로 인식
  43.                     System.out.println("dbValue = " + dbValue + "/ inputValue = " + inputValue);
  44.                 }
  45.             }
  46.         }
  47.     }
  48. }

결과

dbValue = Pusan/ inputValue = seoul 
dbValue = music/ inputValue = game 
dbValue = testDB/ inputValue = test



728x90
반응형

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

util.Date vs sql.Date 차이  (0) 2014.07.01
JSP 용량초과? 65535 bytes limit  (0) 2013.11.21
Integer.paserInt 를 사용한 진법 변환  (0) 2013.11.12
Null Object 사용  (0) 2013.07.05
Singleton Pattern  (0) 2013.07.03

+ Recent posts