<?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:mongo="http://www.springframework.org/schema/data/mongo"

xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">


mongoTemplate에 주입시키기 위해서 사용

<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">

<constructor-arg ref="mongoDbFactory"/>

</bean>

MakeHttp 객체를 spring 에서 관리하기 위해서 등록 , 변수로 mongoTemplate 을 주입

<bean id="makeHttp" class="httpClient.MakeHttp">

<constructor-arg ref="mongoTemplate"></constructor-arg>

</bean>

mongoDbFactory 에 이름 , DB이름 , host , port , username , password 설정

<beans profile="default">

<mongo:db-factory id="mongoDbFactory" dbname="incatable" host="127.0.0.1" port="27017"

username="inca" password="1"/>

</beans>

</beans>


블로그 이미지

김진리

,

DB 인 admin 안에 계정을 만들어야 합니다.

1. 먼저 use admin 으로 접근하여 사용자 계정을 추가 합니다.

ex) inca , 1 로 생성합니다.

2. auth 를 하기 전엔 show dbs 하였으나 실패했다고 합니다.

3. auth요청을 한 후에는 사용이 가능합니다.


MongoDB Server 작동시

--auth 를 추가한다.



블로그 이미지

김진리

,
블로그 이미지

김진리

,

DB 삭제 하기

show dbs 로 현재 db들의 목록을 확인한다.

admin , incadb,incatable,local,test 의 목록을 볼수 있다. 

여기서 incadb 를 삭제 하려고 한다. 먼저 

1. use incadb 로 접속하여 사용을 한다.

2. db.dropDatabase();  - 현재 접속한 db를 삭제 한다.



collection 삭제 하기

db.collection.remove();



블로그 이미지

김진리

,


속성에서 글꼴을 굴림체로 하면됩니다.


굴림체 속성이 없으면 c:\windows\system32 폴더에 있는 cmd 를 직접 실행 시키면 굴림체 가 나옵니다.

블로그 이미지

김진리

,

사용자 등록

db.addUser("아이디","비번");

접속가능 여부

db.auth("아이디","비번");  가능할시 1을 반환

암호 변경시

db.addUser("아이디","바꿀비번");

계정 삭제시

db.removeUser("아이디");


DB 사용 및 생성  - 없을시 생성 , 존재시 사용

use "db명"

모든 DB검색

show dbs


DML  - 데이터 조작시 

insert

db."콜렉션명".insert( { 칼럼 : "값" } );    ex ) db.student.insert( { name : "lee"} );

select All  - 전체 검색

db."콜렉션명".find();       ex ) db.student.find();

delete

db."콜렉션명".remove( { 칼럼 : "값" } );    ex ) db.student.remove( { name : "lee" } );


블로그 이미지

김진리

,

MongoDB


DataBase 는 DB 그대로 이고

Table의 개념은 Collection 이다.


ex)  db = kim  table = student  라는 예제로 테이블 접근.

use kim

db.student.find();


db를 사용하기위해선 use 데이터베이스명

검색이나 삭제를 하기위해선 db.콜렉션명.find();


블로그 이미지

김진리

,

현재 Spring maven 에 tomcat lib 를 추가하여 생기는 에러이다.

2가지 방법이 있다.


첫번째.

http://stackoverflow.com/questions/8487048/java-lang-linkageerror-javax-servlet-jsp-jspapplicationcontext-getexpressionfac  글 참고

That will happen when you include server-specific libraries of a different server make/version in the/WEB-INF/lib of your web application, such as jsp-api.jarel-api.jarservlet-api.jar, etc. You need to remove them all. The /WEB-INF/lib should not contain any server-specific libraries. They belongs in the specific server itself (Tomcat has them in its /lib folder already).


자신의 톰캣 서버의 lib를 사용하면 에러가 나지 않는다.

Project -> Properties -> JAVA Build Path -> Libraries -> Add Library -> Server Runtime

Server 추가 한다.



두번째.


pom.xml 에 


<dependency>

<groupId>org.apache.tomcat</groupId>

<artifactId>tomcat-coyote</artifactId>

<version>7.0.39</version>

<scope>provided</scope>

</dependency>



provided - 컴파일 할 때 필요하지만, 실제 런타임 때에는 컨테이너 같은 것에서 기본으로 제공되는 모듈임을 의미한다. 예를 들어, 서블릿이나 JSP API 등이 이에 해당한다. 배포시 제외된다.

 

실제 런타임때에는 컨테이너(JVM)에서 제공되는 api 를 사용해야 하기 때문에 provided 를 사용한다.

ex) tomcat 안에 있는 jar 파일들

'개발자 > Spring' 카테고리의 다른 글

Spring 에서 File Dowload 하는 예제 및 설정  (0) 2013.06.12
스프링 프레임웍 jar 파일  (1) 2013.03.05
Spring 에서 context부분...  (0) 2013.03.04
Spring 기본 환경설정 프로젝트  (0) 2013.03.04
applicationContext.xml  (0) 2013.03.04
블로그 이미지

김진리

,

java 에서 httpclient 를 이용하여 데이터를 보낼시 한글이 ?? 로 깨지는 경우가 발생한다.


한글 처리는 java.net 의 URLEncoder 와 URLDecoder 를 이용해 보낼땐 encode, 받을땐 decode 를 하면 한글이 정상 처리됨을 볼 수 있다.


httpclient file post 방식 예제 )


PostMethod post  = new PostMethod("보낼경로");

String filename = URLEncoder.encode("파일이름");

File file = new file(파일경로);

Part[] parts = { new StringPart("보낼 속성 이름",filename),

new FilePart("보낼 속성 이름",file)

};


post.setRequestEntity( new MultipartRequestEntity(parts,filePost.getParams()));

HttpClient client = new httpClient();

int status = client.executeMethod(post);  <- 실제적으로 경로를 실행하게되고 상태 값이 int status 에 저장하게 된다 200 이 return 되면 성공 404 는 페이지를 찾을수 없다


if( status == HttpStatus.SC_OK) {
    200

}






받을시


String temp = URLDecoder.decode( request.getparameter("속성이름"));

한글 파일 이름이 저장이 된다.

블로그 이미지

김진리

,

MultipartRequest는 다운로드시 2기가 가 넘으면 int 범위때문에 에러가 발생한다.

이러한 부분은 보완하기 위해서 다운로드할시 stream으로 쭉쭉 받으면 되겠다.

apache 에서  stream api를 확인해보니 


// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload();

// Parse the request
FileItemIterator iter = upload.getItemIterator(request);
while (iter.hasNext()) {
   
FileItemStream item = iter.next();
   
String name = item.getFieldName();
   
InputStream stream = item.openStream();
   
if (item.isFormField()) {
       
System.out.println("Form field " + name + " with value "
           
+ Streams.asString(stream) + " detected.");
   
} else {
       
System.out.println("File field " + name + " with file name "
           
+ item.getName() + " detected.");
       
// Process the input stream
       
...
   
}
}

라는 예제를 제시하고 있다.

else 부분이 정상적인 파일이 존재 할시이다.


else 부분에 이벤트를.

String path = 저장경로; FileOutputStream fop = new FileOutputStream(new File(저장경로)); Streams.copy(stream, fop, true);


streams.copy를 사용하면 해당 경로에 파일이 쭉쭉~~ stream 방식으로 저장이 되겠다.


블로그 이미지

김진리

,