1. 참조객체 복사시 주의.

list , array 와 같은 참조객체 복사시 주소값만 복사하는 얕은복사 주의.

참고 : https://developyo.tistory.com/59?category=688588

 

2. Transaction 사용시 주의. 

1) @Transactional 어노테이션이 붙은 A method 가 동일한 클래스 내에 위치한 메소드 B에 의해 호출될 때, A의 트랜잭션 어노테이션은 작동하지 않음.

2) 스프링의 Transaction은 checked exception 은 rollback 대상으로 보지않음.

참고 : https://developyo.tistory.com/51

 

3. overloading 관련

오버로딩은 상속이 되지 않음.

참고 : https://stackoverflow.com/questions/31141834/overloading-method-on-extended-class

 

오버로딩은 컴파일 단계에서.

오버라이딩은 런타임 단계에서.

참고 : http://blog.naver.com/PostView.nhn?blogId=skykingkjs&logNo=150175869201&redirect=Dlog&widgetTypeCall=true

 

4. @value 주입시 주의사항

@Value 필드 주입의 경우 Object 가 생성되고 난 후 주입되므로 

Object 생성자를 타는 시점에선 @Value 값이 null.

@Value 로 주입받은 값을 생성자에서 사용시 @PostConstruct 사용 할 것

참고 : https://stackoverflow.com/questions/46035971/spring-autowired-and-value-on-property-not-working

참고 : https://jeong-pro.tistory.com/167

 

[@PostConstruct 사용법]

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
 
@Component("CustomChatManager")
public class CustomChatManager {
    
    protected final static Logger logger = LoggerFactory.getLogger(CustomChatManager.class);
        
    @Value("#{systemProperties['jboss.service.mode']}")    
    private String CHATJAR;    
 
    private ChatManager cm;
    
    private static final String CHAT_SERVER_LOCAL = "http://1";    //로컬
    private static final String CHAT_SERVER_DEV = "http://2";    //개발 
    private static final String CHAT_SERVER_DEV2 = "http://3";    
    private static final String CHAT_SERVER_OPER = "http://4";    
    
    @PostConstruct    
    public void init() throws Exception{
        this.cm = ChatManager.getInstance();
        this.setServerURI();
    }    
    //채팅서버 URI 세팅
    private void setServerURI() throws Exception {
        
        String uri = CHAT_SERVER_LOCAL;
        
        if(CHATJAR != null) {
            switch(CHATJAR) {
            case "local":
                uri = CHAT_SERVER_LOCAL;
                break;
            case "dev":
                uri = CHAT_SERVER_DEV;
                break;
            case "tb":
            case "bmt":
                uri = CHAT_SERVER_DEV2;
                break;
            case "oper"
                uri = CHAT_SERVER_OPER;
                break;
            default :
                uri = CHAT_SERVER_OPER;
                break;
            }
        }
        
        URI suri = null;
        logger.info("chatjar : " + CHATJAR + "\nchat uri : " + uri);
        
        try {
            suri = new URI(uri);
            cm.setServerURI(suri);
        } catch (URISyntaxException ue) {
            logger.error("set chat jar failed ! : {}" , ue);
            throw ue;
        } catch (Exception e) {
            logger.error("set chat jar failed ! : {}" , e);
            throw e;
        }
    }
    
    public ChatManager getInstance() throws Exception {
        return this.cm;
    }
}
 
cs

 

5. 스프링+멀티스레드 환경에서 멤버변수 선언 주의

Thread safe 하다는 건 public 메소드 안의 로컬 변수가 Thread safe 하다는 의미일 뿐, 멤버변수가 Thread safe 하다는 의미가 아니다.

멤버변수는 주입에 사용되는 Bean 만 사용할 것

참고 : https://beyondj2ee.wordpress.com/2013/02/28/%EB%A9%80%ED%8B%B0-%EC%93%B0%EB%A0%88%EB%93%9C-%ED%99%98%EA%B2%BD%EC%97%90%EC%84%9C-%EC%8A%A4%ED%94%84%EB%A7%81%EB%B9%88-%EC%A3%BC%EC%9D%98%EC%82%AC%ED%95%AD/

 

6. DI 와 new 생성자의 혼용 주의

new 생성자로 A 객체 생성, A 객체 내에서 특정 객체 DI 로 주입받는 경우

DI 에서 null pointer exception 발생.

 

7. Interceptor 내의 멤버변수 사용시 주의

Interceptor 내의 prehandle , posthandle 메소드 내에서 class(Interceptor)의 멤버변수(전역변수)를 사용하여 처리경과시간을 찍을 경우 시간 맞지않음. (prehandle 에서 time set 한 후, posthandle 에서 time get 할 경우 엉터리 시간이 나옴)

context 흐름을 따르므로 prehandle --> ~ --> posthandle 간 흐름에서 parameter 로 들고 다녀야 함

 

8. Interceptor 에서 body 값 출력 주의

Interceptor 에서 body 에 담겨온 클라이언트의 request parameter 를 찍는 경우

실제 요청을 받아 로직을 수행하는 controller 나 service 에서 request parameter를 꺼내 쓸 수 없음.

stream은 1회성이므로 한번 열리면 다시 열어 쓸 수 없음.

--> 위 경우 filter 로 request parameter를 wrapping 하거나, 아예 AOP 로 로그를 찍어야 함.

 

9. DELETE 방식 호출시 주의사항

outputStream 사용하지 말것. 사용시 에러남.

참고 : https://developyo.tistory.com/8?category=688588

 

10. 이너클래스 사용시 주의사항

이너클래스는 바깥쪽에 있는 변수 중, final 로 선언된 변수만 사용이 가능.

 

11. 파일 업로드/다운로드 시 directory 권한 주의

파일을 로컬의 특정 경로 밑에 생성하여 특정 외부 서버에 ftp 로 전송하는 배치가 있을 때,

로컬의 특정 경로에 권한이 어떻게 되어있는지 필히 확인할 것.

만약 로컬의 특정 경로가 root 755 와 같이 되어있어, was계정이 w 가 불가 할 경우 에러발생.

 

12. mybatis version 낮은 경우 update 쿼리에서 selectkey 사용 불가

 

13. git hub repository 연동시 DB 정보를 비롯해 숨겨야 할 정보 유의하여 연동하기

gitignore 작성한 후 repository 연동해야 기록 자체가 남질 않음.

 

 

반응형

+ Recent posts