블로그 이미지
박공명

카테고리

분류 전체보기 (99)
된장 (7)
Dev (60)
Android (14)
Apache (6)
C (1)
Gauce (1)
Java (8)
Javascript (4)
JSP (3)
Mysql (2)
Oracle (3)
PHP (2)
Weblogic (1)
linux (8)
꼐..꼐임 (6)
식탐 (18)
우리 (0)
Etc (8)
개인자료 (0)
Total
Today
Yesterday

spring - mybatis 세팅

Dev/linux / 2014. 1. 22. 18:54

가장먼저 라이브러리 업데이트를 해야된다.

maven 요즘 다들 쓰져?

pom.xml에 해당내용을 추가한다.


  <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>3.2.4.RELEASE</version>
  </dependency>
  <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.26</version>
  </dependency>
  <dependency>
      <groupId>com.kenai.nbpwr</groupId>
      <artifactId>org-apache-commons-dbcp</artifactId>
      <version>1.2.2-201002241055</version>
  </dependency>
  <dependency>
     <groupId>org.mybatis</groupId>
     <artifactId>mybatis</artifactId>
     <version>3.2.2</version>
   </dependency>
   <dependency>
     <groupId>org.mybatis</groupId>
     <artifactId>mybatis-spring</artifactId>
     <version>1.2.0</version>
   </dependency>

 

저장하면 자동으로 라이브러리가 업데이트된다.

그후에 mybatis 환경파일을 만든다.

 

<?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"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
  
    <context:component-scan base-package="com.pgmman.webmvc"/>

    <context:property-placeholder location="classpath:jdbc.properties"/>
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${jdbc.driverClassName}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>
 
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="typeAliasesPackage" value="com.pgmman.webmvc.vo"/>
        <property name="mapperLocations" value="classpath*:com/pgmman/webmvc/mapper/*.xml"/>
    </bean>


    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg index="0" ref="sqlSessionFactory"/>
    </bean>
   
 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
   <property name="dataSource" ref="dataSource"/>
 </bean>
 <tx:annotation-driven transaction-manager="transactionManager" />

</beans>

 

중간에 환경파일이 하나 있을것이다 jdbc.properties 요놈을 생성해준다.

 

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost/gmProject
jdbc.username=비밀

jdbc.password=비밀

 

마지막으로 web.xml 에 해당 환경을 읽도록 추가해준다.

전부 다읽도록 수정했다.

 

 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>
  /WEB-INF/spring/*-context.xml
  </param-value>
 </context-param>

 

테스트해야지.

 

테스트할 쿼리를 user.xml에 생성했다.

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="user">

  <select id="getUserList" resultType="UserInfoVO">
   SELECT user_id,user_name
   FROM user
  </select>

</mapper>

 

dao도 생성한다.

 

@Repository
public class UserInfoDao {

  @Autowired
  private SqlSession sqlSession;

  public List<UserInfoVO> getUserList() {

   return sqlSession.selectList("user.getUserList");

  }

}

 

service생성한다.

 

@Service
public class UserInfoService {

  @Autowired
  private UserInfoDao userInfoDao;

  public List<UserInfoVO> getUserList() {

   return userInfoDao.getUserList();

  }

}

 

Controller생성한다.

@Controller
public class BoardController {
 
 @Autowired
 private UserInfoService userInfoService;

 private static final Logger logger = LoggerFactory.getLogger(BoardController.class);
 
 @RequestMapping(value = "/board.gm", method = RequestMethod.GET)
 public String home(Locale locale, Model model) {
  logger.info("Welcome board!! The client locale is {}.", locale);
  
  Date date = new Date();
  DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
  
  String formattedDate = dateFormat.format(date);
  
  model.addAttribute("serverTime", formattedDate );
  model.addAttribute("userList", userInfoService.getUserList());

  return "board";
 }

}

 

화면 생성한다.

 

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" pageEncoding="utf-8" %>
<%
 //UserInfoVO user;
 //user = request.getAttribute("userList");
%>
<html>
<head>
 <title>Board</title>
</head>
<body>
<h1>
 Hello world! 
</h1>

<P>  The time on the server is ${serverTime}. </P>

    <c:forEach var='user' items='${userList}'>
     ${user.user_id}/${user.user_name}<br>
    </c:forEach>
</body>
</html>

 

자 그럼 보일것이다.

 

 

 

 

끝.

 

Posted by 박공명
, |

일단 설치를 한다

 

apt-get install mysql-server mysql-client

 

설치중에 비밀번호를 입력한다.

설치후에 접속해서 기초적인 설정을 한다.

 

mysql -p

 

암호치고 

 

디비와 유저를 생성해준다.

 

mysql> create database gmproject;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| gmproject          |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.01 sec)

mysql> grant select,insert,update,delete,create,drop,alter on gmproject.* to 'pgmman'@'%' identified by '비밀';
Query OK, 0 rows affected (0.01 sec)

mysql>
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

 

exit로 종료하고

생성한 아뒤로 접속하면된다.

 

root@raspberrypi:/usr/local/apache-tomcat-6.0.37/webapps/web# mysql -u pgmman -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 51
Server version: 5.5.33-0+wheezy1 (Debian)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use gmproject
Database changed

 

자 나는 한단계 더가서

기존 사용하던 디비의 정보를 새로 설치한 서버에 옮기고싶다.

기존 윈도우 시스템에서 백업을 수행한다.

 

E:\APPLICATION\mysql-5.1.48\bin>mysqldump -uroot -p gmproject > gmproject.sql
Enter password: *******

E:\APPLICATION\mysql-5.1.48\bin>dir *.sql
 E 드라이브의 볼륨: MAIN_APP
 볼륨 일련 번호: F862-C7B4

 E:\APPLICATION\mysql-5.1.48\bin 디렉터리

2014-01-22  오후 03:51            13,906 gmproject.sql
               1개 파일              13,906 바이트
               0개 디렉터리  17,593,155,584 바이트 남음

E:\APPLICATION\mysql-5.1.48\bin>

 

전에 설치한 ftp서버를 통하여 백업파일을 업로드한다.

그담에 복원명령어 치면 끝

 

root@raspberrypi:/home/pi# mysql -u root -p gmproject < ./gmproject.sql
Enter password:
root@raspberrypi:/home/pi# mysql -upgmman -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 54
Server version: 5.5.33-0+wheezy1 (Debian)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use gmproject
Database changed
mysql> show tables;
+---------------------+
| Tables_in_gmproject |
+---------------------+
| board               |
| developer           |
| menu                |
| uploadfiles         |
| user                |
+---------------------+
5 rows in set (0.01 sec)

mysql>

정상적으로 들어왔다.
 

Posted by 박공명
, |

java를 설치한다.

 

apt-get install openjdk-7-jdk

 

설치됬다.

 

환경변수를 등록해준다.

 

root@raspberrypi:/usr/lib/jvm# nano /etc/profile

아래 라인을 추가

 

export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-armhf"

그리고 등록 후 확인한다.

 

root@raspberrypi:/usr/lib/jvm# source /etc/profile
root@raspberrypi:/usr/lib/jvm# echo $JAVA_HOME
/usr/lib/jvm/java-7-openjdk-armhf

이제 톰캣을 받는다.


root@raspberrypi:/usr/local# wget http://apache.mirror.cdnetworks.com/tomcat/tomcat-6/v6.0.37/bin/apache-tomcat-6.0.37.tar.gz
--2014-01-21 11:12:39--  http://apache.mirror.cdnetworks.com/tomcat/tomcat-6/v6.0.37/bin/apache-tomcat-6.0.37.tar.gz
Resolving apache.mirror.cdnetworks.com (apache.mirror.cdnetworks.com)... 61.110.198.174
Connecting to apache.mirror.cdnetworks.com (apache.mirror.cdnetworks.com)|61.110.198.174|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6885442 (6.6M) [application/x-gzip]
Saving to: `apache-tomcat-6.0.37.tar.gz'

100%[=====================================================================>] 6,885,442   2.06M/s   in 3.2s

2014-01-21 11:12:42 (2.02 MB/s) - `apache-tomcat-6.0.37.tar.gz' saved [6885442/6885442]

 

이제 다운로드받은 톰캣을 압축을 푼다.

 

tar -zxvf apa~(tab누르면 자동완성된다)

 

자동실행되게한다.

 

nano /etc/rc.local

 

아래처럼

 

/usr/local/apache-tomcat-6.0.37/bin/startup.sh

 

이제 아파치를 설치한다.

 

apt-get install apache2

 

apt-get install libapache2-mod-jk

 

환경설정파일을 편집해서 jk module을 사용하도록 추가한다.

 

root@raspberrypi:/etc/apache2# nano apache2.conf

#JK_MODULE
LoadModule jk_module /usr/lib/apache2/modules/mod_jk.s

 

jk module사용하여 넘길 패턴을 설정할수있도록 해당 파일을 수정한다.


root@raspberrypi:/etc/apache2# cd sites-enabled/
root@raspberrypi:/etc/apache2/sites-enabled# ls
000-default
root@raspberrypi:/etc/apache2/sites-enabled# nano 000-default

해당 내용을 추가해 넣는다. 무식하게 똑같이 따라넣는건 아니다.


JkMount /*.jsp ajp13_worker
JkMount /*.gm ajp13_worker

 

로컬호스트에 접속했을떄 It work! 뭐 이런말 뜨면 apache가 정상작동 하고있는상황

로컬호스트/index.jsp 로 접속시 톰캣이 뜨면 연동성공한거다.

요렇게

 

 

 

 

어? 끝!

Posted by 박공명
, |

이왕이면 업데이트부터 한다.

 

apt-get update

apt-get upgrade

 

어... 생각보다 오래걸렸음.

 

ftp를 설치한다.

 

root@raspberrypi:~# apt-get install vsftpd

환경설정파일을 편집한다.

 

root@raspberrypi:~# nano /etc/vsftpd.conf

참고할내용.

# FTP서버 와 외부 접속 허용여부

listen=YES

# 익명 로그인 설정

anonymous_enable=NO

# 로컬 접속 여부설정

local_enable=YES

# 쓰기(업로드)기능설정

write_enable=YES

# 업로드 후, 폴더권한 자동설정(777=자동설정)

local_umask=022

# 본인 외 계정폴더 접속 설정

chroot_list_enable=YES

# chroot_list 파일경로 지정

chroot_list_file=/etc/vsftpd.chroot_list

# passwd 파일에 등록된 대로 chroot를 실행여부

passwd_chroot_enable=YES

# chroot를 위해 root디렉토리를 설정

local_root=/home/

환경설정후 재시작해준다
root@raspberrypi:~# service vsftpd restart
Stopping FTP server: vsftpd.
Starting FTP server: vsftpd.

 

Posted by 박공명
, |

8기가 메모리에 라즈베리파이를 설치했는데

 

알고보니 2기가만 쓰고있었다는 사실.

 

root@raspberrypi:/# df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          1.8G  1.7G     0 100% /
/dev/root       1.8G  1.7G     0 100% /
devtmpfs        116M     0  116M   0% /dev
tmpfs            25M  244K   25M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            50M     0   50M   0% /run/shm
/dev/mmcblk0p1   56M   19M   38M  33% /boot
tmpfs            50M     0   50M   0% /tmp

파티션 리스트를 확인하고

 

root@raspberrypi:/# fdisk -l

Disk /dev/mmcblk0: 7948 MB, 7948206080 bytes
4 heads, 16 sectors/track, 242560 cylinders, total 15523840 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c7b31

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          122880     3788799     1832960   83  Linux

fdisk를 실행한다.

 

root@raspberrypi:/# fdisk -u -c /dev/mmcblk0

delete - 파티션2 - new - primary - 파티션2 - 시작섹터~종료섹터 순서로 입력한다.

 

Command (m for help): d
Partition number (1-4): 2

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (1-4, default 2): 2
First sector (2048-15523839, default 2048): 122880
Last sector, +sectors or +size{K,M,G} (122880-15523839, default 15523839): 15523839

 

그냥 enter 치면 default로 자동세팅된다.

 

저장하고 종료

 

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

그리고 재부팅.

 

파티션 재인식후 확인.

 

root@raspberrypi:~# resize2fs /dev/mmcblk0p2
resize2fs 1.42.5 (29-Jul-2012)
Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mmcblk0p2 is now 1925120 blocks long.

root@raspberrypi:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          7.3G  1.7G  5.3G  25% /
/dev/root       7.3G  1.7G  5.3G  25% /
devtmpfs        116M     0  116M   0% /dev
tmpfs            25M  240K   25M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            50M     0   50M   0% /run/shm
/dev/mmcblk0p1   56M   19M   38M  33% /boot
tmpfs            50M     0   50M   0% /tmp

끝.


 

'Dev > linux' 카테고리의 다른 글

라즈베리파이 리눅스 아파치 톰캣 설치  (0) 2014.01.21
라즈베리파이 리눅스 ftp서버 설치  (0) 2014.01.21
라즈베리파이 라즈비안 xbmc  (6) 2013.07.16
nslookup option , 사용법  (2) 2011.06.15
linux favorite command  (0) 2011.03.08
Posted by 박공명
, |

여름 어느날 갑자기 강림한 지름신...

아무생각 없이 질렀다.

주문내역엔 걍 리더라고 써있는데 sd카드형태가 아닌 usb가 와서 고생한건 안비밀.


 

 

가장 먼저 한 일은 키보드와 마우스를 제거하는 것이다.

n100mini 인가 iptime의 무선 랜카드를 인식 시킨 후에 데스크탑에서 작업하는것이다.


 

 

세팅이 완료된 후(라즈비안,XBMC를 설치 하였다.)

라즈베리파이는 거실로 옮겨졌다.

저렇게 티비옆에 전원과 HDMI 케이블만이 연결된 상태다.


 

 

자 개쩌는 안드로이드 SSH를 통하여 이제는 데스크탑도 필요없다.

폰만 있으면 XBMC를 켜고 종료할수 있도록 실행파일을 생성하였다.

보시는분들 쓸수 있도록 명령어 공개함. 모를린 없겟지만...


 

 

그다음으로 한 일은 데스크탑의 네트워크를 통한 공유 (SMB) 이다.

다 쉽다.

안드로이드 XBMC 리모콘은 여러 종류가 있는데 Yatse 라는 이름이 내가보기엔 best. (현재 기준으로)

설치하고나면 유투브, 네이버의 동영상 마저도 라즈베리파이와 연결된 TV로 공유재생이 가능하다.


 

문제점이라면 SMB를 통한 동영상 재생시 10초마다 끊긴다. 한 10초동안...  기기탓인지 SMB로 가져올때 부담이 있는지

모르겠는데 유투브 공유를 통해서 재생시킬시 굉장히 부드럽게 잘 작동하는걸 봐서는 내쪽 설정이나 환경에 문제가

있는가 싶다.

이로써 거실에 누워서 손가락만 까딱 해서 xbmc켜고 동영상 재생까지 가능한 환경이 완료되었다.

참 좋다 함 해 보시라.


 

Posted by 박공명
, |

nslookup option , 사용법

Dev/linux / 2011. 6. 15. 12:12


이름그대로 네임서버를 확인하는 프로그램입니다.

너무 널리사용하는놈이라 대부분의 플랫폼에서 다있는 명령어죠.

DNS에서 호스트에대한 정보를 얻어오게됩니다.

NAME
       nslookup - query Internet name servers interactively

SYNOPSIS
       nslookup [-option] [name | -] [server]

기본적인 사용법
gm.park@ubuntuServer:~$ nslookup -q=host 213.165.65.50
unknown query type: host
Server:         165.243.137.23
Address:        165.243.137.23#53

Non-authoritative answer:
50.65.165.213.in-addr.arpa      name = gmx.net.

Authoritative answers can be found from:
65.165.213.in-addr.arpa nameserver = ns.schlund.de.
65.165.213.in-addr.arpa nameserver = dns.gmx.net.
ns.schlund.de   internet address = 195.20.224.97
dns.gmx.net     internet address = 213.165.64.1

--------------------------------------------------------------
gm.park@ubuntuServer:~$ nslookup -querytype=mx gmx.de
Server:         165.243.137.23
Address:        165.243.137.23#53

Non-authoritative answer:
gmx.de  mail exchanger = 10 mx1.gmx.net.
gmx.de  mail exchanger = 10 mx0.gmx.net.

Authoritative answers can be found from:
gmx.de  nameserver = ns-gmx.ui-dns.de.
gmx.de  nameserver = ns-gmx.ui-dns.biz.
gmx.de  nameserver = ns.schlund.de.
gmx.de  nameserver = dns.gmx.net.
ns.schlund.de   internet address = 195.20.224.97
dns.gmx.net     internet address = 213.165.64.1
ns-gmx.ui-dns.de        internet address = 217.160.80.199
ns-gmx.ui-dns.biz       internet address = 217.160.81.199

옵션은 어차피 쓰는거만 쓰게된다
상세한 옵션은 자체메뉴얼을 보면서 확보하자

NS
 도메인의 네임서버 정보
MX
 도메인의 MX(Mail Exchanger) 서버
A
 호스트의 IP주소
CNAME
 별칭으로 부여된 canonical name
SOA
 도메인의 start-of-authority정보
HINFO
 호스트의 CPU 정보와 운영체제 정보
MINFO
 메일박스와 메일 리스트 정보
PTR
 IP주소에 대한 호스트명
TXT
 호스트에 대한 텍스트 정보
UNIFO
 사용자 정보
ANY
 호스트에 관련된 모든 레코드들의 정보

Posted by 박공명
, |

linux favorite command

Dev/linux / 2011. 3. 8. 17:23

사용자가 bash를 사용할때 읽어오는 파일들
.profile : basic infomation
.bashrc : bash infomation
.bash_history : have bash command history
.bash_logout : when logout, system execute this command.(clear tmp,make history)
file :
if no have home directory, system use /etc/profile file.
% Order of execution
execute shell -> bash_profile  -> bashrc | bash_logout(when logout)

~ : $HOME
- : previous directory
export : 지정된 환경보기

와일드카드
* : 모든문자
? : 한개의문자
[abc] : a,b,c중한개
[a-z] : a-z까지의 모든문자
[:alnum:] : 알파벳과숫자 
[:alpha:] : 알파벳
[:digit:] :숫자
[:upper:] : 알파벳대문자
[:lower:] : 알파벳소문자

brace expansion
$echo a{1,2,3}
a1 a2 a3
$ echo a{1{1,2,3},2{1,2,3},3{1,2,3}}
a11 a12 a13 a21 a22 a23 a31 a32 a33

I/O redirection
> out : out으로 출력
< in : in으로부터 입력
>> out : out으로 이어붙임
2> :  표준에러의 출력방향
1> : 표준출력
2>&1 : 에러를 표준출력과같이 출력
1>&2 : 표준출력을 에러와같이 출력

pipeline
$ls | more
is
ls > tmp -> more < tmp

background job
find . -name "findname" 2>&1 > output &
find의결과물중 에러를 표준출력과 합치며 표준출력은 output파일로전달하며 백그라운드로작업
nohup
&는 일반적으로 터미널이 기동중에서만 프로세서를 잡고있게되는데
nohup는 터미널이 종료해도(hang up signal) 잡고있게된다.
특정 flag를 통하여 &를 nohup과 동일하게 쓸수있다.
$shopt | grep huponexit
huponexit       off

emacs 편집기능
^b : previous cursor
^f : next cursor
del : delete left character
^d : delete right character
^a : move front
^e : move end
^k : delete from this position to end
^p : move previous command
^n : move next command


테스트했던 예제
echo num of the parameter : $#
echo parameter string     : $@
echo param1 : $1 param2 : $2 param3 : $3
if [ $# > 1 ]; then
 param=$1
 echo param1 substring1to3 : ${param:0:3}
fi
for arg in "$@"
do
 echo ${arg}
done
echo "if test"
BUILD_USERMODE="true"
RESULTMY=if [ "$BUILD_USERMODE" == "qqqq" ];
echo "RESULTMY = $RESULTMY"
if [ "$BUILD_USERMODE" == "true" ]; then
 echo "it's true"
 echo "return is $?"
else
 echo "it's false"
 echo "return is $?"
fi
echo "result = $RESULT"

:= 이건가보다.



Posted by 박공명
, |

최근에 달린 댓글

최근에 받은 트랙백

글 보관함