2015년 10월 5일 월요일

spring jpa 설정 및 테스트 (maven 설정)

거의 대부분 mybatis 를 이용하여 개발을 하는데..
JPA가 대세라고 해서 가벼운 프로젝트에 연동을 해봤습니다.

1. 라이브러리 import....
maven pom.xml


   org.springframework.data
   spring-data-jpa
   1.9.0.RELEASE


   org.hibernate
   hibernate-entitymanager
   4.3.8.Final



2. Entity class를 만들어 줍니다.
참고로 SerializedName, Expose는 jpa와 직접 관련은 없습니다.. (개체를 그대로 JsonView 할때 사용)

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import javax.persistence.*;

@Entity
@Table(name="tb_notice")
public class Notice {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "notice_id")
    @SerializedName(value = "notice_id")
    @Expose
    private Integer noticeId;

    @Column(name="title", nullable = false)
    @Expose
    private String title;

    @Column(name="content", nullable = false)
    @Expose
    private String content;

    @Column(name="reg_date", nullable = false)
    @SerializedName(value = "reg_date")
    @Expose
    private String regDate;

    @Column(name="del_yn", nullable = false)
    @Expose(serialize = false, deserialize = false)
    private String delYn;

    public Integer getNoticeId() {
        return noticeId;
    }

    public void setNoticeId(Integer noticeId) {
        this.noticeId = noticeId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getRegDate() {
        return regDate;
    }

    public void setRegDate(String regDate) {
        this.regDate = regDate;
    }

    public String getDelYn() {
        return delYn;
    }

    public void setDelYn(String delYn) {
        this.delYn = delYn;
    }
}



3. repository 를 만들어줍니다. (아무것도 없는게.. 인상적)

public interface NoticeRepository extends JpaRepository<Notice, Integer> {

}



4. context-jpa.xml 설정합니다. (txManager2인 이유는 기존에 mybatis에 영향을 주지 않기 위해서입니다. , mybatis를 한번에 다 걷어낼 자신이 없...)




    
    
        
        
    

    
        
            
            
        
    

    
        
            
            
        
    

    
        
        
    

    
    
        
            
                
                
            
        
    

    
    





5. 사용 예제

@Service
public class NoticeService extends ServiceBase  {
    private static final Logger logger = LoggerFactory.getLogger(NoticeService.class);

    @Autowired
    private NoticeRepository noticeRepository;

    public void srXX(RequestData req, ResponseData res) throws Exception {
        List<Notice> list = noticeRepository.findAll();
        res.put("notice_list", list);
    }
}


인터넷상에 자료가 많아서 설정은 어렵지 않았습니다.
하지만 실제로 사용에 요령이 필요하다고 하네요.. (제대로 이해를 하지 않고 사용하면 성능에도 영향을 준다고 함)

2015년 9월 20일 일요일

redis 3.0.4 설치


컴파일러를 먼저 설치해야 합니다. (설치돼 있다면 패스)

yum install gcc gcc-c++ autoconf automake


참고) http://www.redis.io/download


# 다운로드 및 설치 (컴파일)
wget http://download.redis.io/releases/redis-3.0.4.tar.gz
tar xzf redis-3.0.4.tar.gz
cd redis-3.0.4
make && make install
cd utils
./install_server.sh

# redis-6379로 서비스가 만들어져 있을껀데.. 사용하기 좋게 redis로 이름 바꿔줍니다.
mv /etc/init.d/redis-6379 /etc/init.d/redis

service redis start

# chkconfig redis on 하면 부팅시 자동 실행됩니다.



2015년 9월 16일 수요일

.NET Framework 4.5.2로 개발했다가. 4.0로... 내림

최근에 윈도우 어플을 개발할 일이 생겼다.

.NET 4.5부터 async 문법이 새로 들어갔다 해서.. 이왕 하는거 4.5.2로... 만들기로 했다.
오...... 엄청나게 편리하다.!!

async, await 두개가 중요하다.
특히 UI프로그램에서 background thread와 main thread와의 동기화를 쉽게 지원한다.

아래는 id/pwd를 입력받아서 서버통신으로 인증을 진행하는 코드다.


private async void btnLogin_Click(object sender, RoutedEventArgs e)
{
    string id = tbEmail.Text;
    string pwd = tbPassword.Password;

    SetControlEnableState(false);
    bool isSuccess = await Task.Run<bool>(() =>
    {
        try
        {
                    // 여기가 네트워크 통신을 하는 부분이다.
            _dataCore.DoLogin(id, pwd);
            return true;
        }
        catch (Exception x)
        {
            ErrorHandler.ErrorDump(x, true);
            return false;
        }
        });

    if (!isSuccess)
    {
        SetControlEnableState(true);
        return;
    }
}

보면 알겠지만 client이벤트에서 바로 ... 별도 쓰레드 동기화 없이.. 로그인 처리를 모두 완료했다.


오늘 테스트를 진행하는데...
.NET Framework 4.5 깔린... PC가.. 많이 없네.....

... 그래서.. 4.0으로.. BackgroundWorker 사용해서 재개발했다...

그지 같네... (화면이 세개인 프로그램이라 다행)

2015년 9월 15일 화요일

디지탈오션에 서버 셋팅기 (centos 6.7)


친구랑 개발하는 간단한 쪽지앱의 서버로 사용할 서버를 구축했다.
물론 나는 잘 모른다 모든건 다 구글을 통해..

1. SWAP 메모리 할당
참고) https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-centos-6

dd if=/dev/zero of=/swapfile bs=1024 count=2048k
mkswap /swapfile
swapon /swapfile
chown root:root /swapfile 
chmod 0600 /swapfile


아래 내용을 /etc/fstab 에 붙인다.

/swapfile          swap            swap    defaults        0 0



2. 서버 시간을 KST 로 바꿈 & rdate 설치

ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
yum install rdate



3. java 1.7설치 rpm
http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html
위에서 64비트 linux용으로 다운받는다.

rpm -ivh jre-7u80-linux-x64.rpm


4. 위와 같은 방법으로 rabbitMQ 서버도 설치

rpm -ivh erlang-17.4-1.el6.x86_64.rpm
rpm -ivh rabbitmq-server-3.4.4-1.noarch.rpm


/etc/rabbitmq/rabbitmq-env.conf 파일 만들고 nodename 지정

NODENAME=samplenode


관리자 페이지 플러그인 활성화 & 서버 시작

rabbitmq-plugins enable rabbitmq_management
rabbitmq-server -detached




사용자 추가, id/pwd 지정하기 권한 주기
참고) https://www.rabbitmq.com/man/rabbitmqctl.1.man.html#

rabbitmqctl add_user {username} {password} 
rabbitmqctl set_user_tags {username} administrator 


http://hostname:15672/ 에 접속하여 admin메뉴에서 guest 계정 삭제
신규 worker 계정 추가


5. tomcat 7 설치
tar 다운로드 하여 /usr/local/ 에 압축을 풀고.

ln -s apache-tomcat-7.0.57 tomcat


6. mariadb 설치
http://zetawiki.com/wiki/%EB%A6%AC%EB%88%85%EC%8A%A4_MariaDB_%EC%84%A4%EC%B9%98 참고
아래 파일을 생성하고 내용을 작성
/etc/yum.repos.d/MariaDB.repoMariaDB.repo


[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1



yum install MariaDB-server MariaDB-client

#나중에 추가됨 (기본 설정 파일 적용)
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf


7. apache 설치

yum install httpd
yum install mod_ssl


8. iptables 설정
아래 좋은 글이 있어 참고하여 아래와 같이 작성 했다.
출처) http://webdir.tistory.com/170


#!/bin/bash
# iptables 설정 자동화 스크립트
# 입맛에 따라 수정해서 사용합시다.
iptables -F

# TCP 포트 22번을 SSH 접속을 위해 허용
# 원격 접속을 위해 먼저 설정합니다
iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT

# 기본 정책을 설정합니다
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT

# localhost 접속 허용
iptables -A INPUT -i lo -j ACCEPT

# established and related 접속을 허용
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# 기타 사용하는 포트 허용
# -s sourceIP 를 추가 하여 특정 아이피만 가능하도록 할 수 있다.
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
iptables -A INPUT -p tcp --dport 15672 -j ACCEPT

# 설정을 저장
/sbin/service iptables save

# 설정한 내용을 출력
iptables -L -v

2015년 8월 27일 목요일

spring batch 사용

최근에 spring-batch를 사용해 봤는데.. 결과는 성공적 특히 트랜잭션commit size와 read size를 따로 지정할 수 있다는게 좋은것 같다.

쿼리나 기타 로직보다 아래 설정이 중요한 듯 하여 아래 설정을 기록으로 남긴다.

job에 대해서 요약하면
# reader에서 데이타를 읽어서 process 에서 처리 하고 writer로 결과를 기록 한다.

물론 위 설정 외에 각 시작 구간마다 이벤트를 받아 처리 할 수 있는 listener 같은 것도 제공한다.

reader, writer는 커스텀 하지 않고 mybatis에서 기본으로 제공하는 걸 이용했다.
참고) https://mybatis.github.io/spring/ko/batch.html




    



  




    
        
            
         
     
 





  
    
    




2015년 7월 1일 수요일

jfreeChart 에서 한글 깨질때 centos 폰트 설정

jfreeChart를 사용하는 중인데 tomcat위에서 돌리면 한글이 ㅁㅁㅁ 과 같이 나온다.

아래와 같이 한글 폰트를 os에 설치 한다. (물론 코드에서는 폰트 명을 지정해야 한다.)


yum install -y kde-i18n-Korean
yum install -y fonts-korean
fc-cache -fv

반영을 위하여 꼭 tomcat을 재시작 해야 한다.

2015년 6월 4일 목요일

OSX 10.10.3 homebrew 설치하기

터미널 열고


ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"



gimjonghuiui-MacBook-Pro:bin paper$ brew -v
Homebrew 0.9.5


출처: http://coolestguidesontheplanet.com/installing-homebrew-os-x-yosemite-10-10-package-manager-unix-apps/