1 / 14

6 장 . JNDI(Java Naming and Directory Interface)

6 장 . JNDI(Java Naming and Directory Interface). 6-1. JNDI 사용하기 . 6-2. JNDI 네이밍 서비스에 객체 등록하기 6-3. JNDI 네이밍 서비스에 등록된 객체 사용하기 6-4. JNDI 네이밍 서비스에 등록된 객체의 갱신. JNDI 란. 분산환경 EJB 의 엔터프라이즈란 분산환경을 의미함 컴퓨터 여러 대에 서버가 분산되어 운영된다는 것을 의미함 이때 각각의 서버는 객체를 공유할 방법이 필요. JNDI 란. 네이밍 서비스

Download Presentation

6 장 . JNDI(Java Naming and Directory Interface)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 6장. JNDI(Java Naming and Directory Interface) 6-1. JNDI 사용하기. 6-2. JNDI 네이밍 서비스에 객체 등록하기 6-3. JNDI 네이밍 서비스에 등록된 객체 사용하기 6-4. JNDI 네이밍 서비스에 등록된 객체의 갱신

  2. JNDI 란 • 분산환경 • EJB의 엔터프라이즈란 분산환경을 의미함 • 컴퓨터 여러 대에 서버가 분산되어 운영된다는 것을 의미함 • 이때 각각의 서버는 객체를 공유할 방법이 필요

  3. JNDI 란 • 네이밍 서비스 • 대표적이 예로 도메인명을 IP로 바꿔주는 서비스 • 분산된 환경에서 특정한 이름으로 객체를 등록해서 관리할 수 있는 방법 • 예) JDBC 실습에서 DataSource를 “ora9”, “mysql9”등으로 등록하여 사용함

  4. JNDI 란 • JDNI • 자바에서 객체를 네이밍 서비스에 등록, 삭제, 검색을 할 수 있는 방법 • 여러 대의 서버간에는 JNDI를 이용하여 객체를 등록하고, 참조하여 이용됨

  5. JNDI 란 • 문제점 • JNDI lookup()을 사용해서 객체를 참조시, 과부하가 발생 • JSP/서블릿에서는 init() 메소드를 사용함 (JSP/서블릿이 처음 실행될 때 한번만 실행됨)

  6. 6-1. JNDI 사용하기 • JNDI를 사용하는 클라이언트는 • javax.naming 패키지 안의 클래스를 이용 • import javax.naming.*; 선언 • javax.naming.Context 인터페이스 • 기본적인 JNDI 객체 • JNDI 네이밍 서비스에 사용할 객체를 추가, 삭제, 검색할 수 있는 메소드를 가짐

  7. 6-1. JNDI 사용하기 • 웹로직 내부에서 JNDI를 이용할 경우에는 • javax.naming.InitialContext 객체를 생성하여 사용 javax.naming.Context ctx = new javax.naming.InitialContext(); • 우리가 사용한 코드상에서 사용은.. import javax.naming.*; Context ctx = new InitialContext();

  8. 6-1. JNDI 사용하기 • 웹로직 서버 외부에서 동작하는 JSP/서블릿 혹은 엔터프라이즈 빈즈에서 JNDI를 이용할 경우 java.util.Properties p = new java.util.Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); p.put(Context.PROVIDER_URL, "t3://localhost:7001"); javax.naming.Context ctx = new javax.naming.InitialContext(p);

  9. 6-1. JNDI 사용하기 import java.util.Properties; import javax.naming.*; Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); p.put(Context.PROVIDER_URL, "t3://localhost:7001"); Context ctx = new InitialContext(p);

  10. 6-1. JNDI 사용하기 • java.util.Properites 객체에 전달하는 Properties Key값의 의미

  11. 6-1. JNDI 사용하기 • JNDI 네이밍 서비스를 하는 서버의 주소가 변경된 경우 소스를 수정하고 재컴파일 해야함 • 이를 해결하기 위해 소스에는 Context ctx = new InitialContext(); • Jre 폴더 아래의 lib 폴더에 jndi.properties 파일 작성 Java.naming.factory.initial = weblogic.jndi.WLInitialContextFactory Java.naming.provider.url = “t3://localhost:7001”

  12. 6-2. JNDI 네이밍 서비스에 객체 등록하기 • JNDI 네이밍 서비스에 객체를 등록하려면 InitialContext객체를 생성한 후, Context가 가지고 있는 bind() 메소드를 이용 Context ctx = new InitialContext(h); ctx.bind(“ksp”, “김성박”); // bind(String, Object) // bind(JNDI 네임, 객체)

  13. 6-3. JNDI 네이밍 서비스에 등록된 객체 사용하기 • JNDI 네이밍 서비스에 등록된 객체를 가져오려면, InitialContext객체가 가지고 있는 lookup()메소드에 JNDI 이름을 인자로 지정 Context ctx = new InitialContext(h); ctx.lookup(“ksp”); // lookup(String) // lookup(JNDI 네임)

  14. 6-4. JNDI 네이밍 서비스에 등록된 객체의 갱신 #1 • JNDI 네이밍 서비스에 등록된 객체의 갱신하려면, InitialContext 객체의 rebind 메소드를 이용 Context ctx = new InitialContext(h); ctx.rebind(“ksp”, “김성박”); // bind(String, Object) // bind(JNDI 네임, 객체)

More Related