Evgeniy Krivosheev Vyacheslav Yakovenko Last update: Feb, 2012 Spring Framework Module 4 – JNDI.

Презентация:



Advertisements
Похожие презентации
Evgeniy Krivosheev Vyacheslav Yakovenko Last update: Feb, 2012 Spring Framework Module 4 – JNDI.
Advertisements

1 © Luxoft Training 2013 Spring Framework Module 10 JMS & EJB.
Evgeniy Krivosheev Andrey Stukalenko Vyacheslav Yakovenko Last update: Nov, 2013 Spring Framework Module 1 - Introduction.
Inner Classes. 2 Simple Uses of Inner Classes Inner classes are classes defined within other classes The class that includes the inner class is called.
1/27 Chapter 9: Template Functions And Template Classes.
Evgeniy Krivosheev Vyacheslav Yakovenko Last update: Feb, 2012 Spring Framework Module 4 – DAO, JDBC.
WEB SERVICES Mr. P. VASANTH SENA. W EB SERVICES The world before Situation Problems Solutions Motiv. for Web Services Probs. with Curr. sols. Web Services.
© Luxoft Training 2013 Using Reflection API in Java.
© 2002 IBM Corporation Confidential | Date | Other Information, if necessary © Wind River Systems, released under EPL 1.0. All logos are TM of their respective.
XjCharts A C++ / Java Statecharts Tool for Developers Experimental Object Technologies
1 © Luxoft Training 2012 Inner and anonymous classes.
© 2005 Cisco Systems, Inc. All rights reserved. BGP v Customer-to-Provider Connectivity with BGP Connecting a Multihomed Customer to Multiple Service.
1 When And How To Make Interfaces Work For You Advanced OO Techniques Alex Herbstritt Principal Software Engineer, Progress Software Session 102.
© 2006 Cisco Systems, Inc. All rights reserved.IP6FD v IPv6 Transition Mechanisms Implementing Dual Stack.
Operator Overloading Customised behaviour of operators Chapter: 08 Lecture: 26 & 27 Date:
Unit II Constructor Cont… Destructor Default constructor.
Loader Design Options Linkage Editors Dynamic Linking Bootstrap Loaders.
© 2006 Cisco Systems, Inc. All rights reserved. HIPS v Configuring Rules Rule Basics.
© 2009 Avaya Inc. All rights reserved.1 Chapter Three, Voic Pro Advanced Functions Module Four – Voic Campaigns.
Copyright 2003 CCNA 4 Chapter 11 Scaling IP Addresses By Your Name.
Транксрипт:

Evgeniy Krivosheev Vyacheslav Yakovenko Last update: Feb, 2012 Spring Framework Module 4 – JNDI

2 Contents Spring integration with JNDI

3 Spring :: Integration with JNDI Basic function of any naming service is to depict understandable object names (such as addresses, identifiers) and link them to objects that are generally used in software. For example, DNS translates computer names ( into IP addresses ( ).

4 Spring :: Integration with JNDI JNDI: Java Naming and Directory Interface JNDI is used for mapping the object names in the distributed system

5 Spring :: JNDI JNDI directory operations: // get the Initial Context Context ctx = new InitialContext(); // bind object String name = "mary"; String = ctx.bind(name, ); // lookup object String str = (String) ctx.lookup("mary"); // unbind object ctx.unbind(name);

6 Spring :: JNDI new InitialContext()

7 AB AB JNDI repository Name B_NAME to look for B Register in JNDI under the B_NAME Traditional approach: dependencies inside the code Service Locator (JNDI в JEE) pattern: objects in the repository IoC: objects know nothing about each other AB Application context - Creates A object - Initialize - Creates A object -Initialize and inject B object dependency class A { private B b; } class B { } Spring Framework :: JNDI vs. IoC / DI

8 Spring :: Integration with JNDI Generally, referencing to JNDI is needed when it is necessary to access DataSource and JtaTransactionManager. Spring provides rather simple and intuitive way of accessing them:

9 Spring :: Integration with JNDI However, JNDI support in Spring is not limited to this; Main classes used for work with JNDI in Spring are: –org.springframework.jndi.JndiTemplate –Interface org.springframework.jndi.JndiCallback –org.springframework.jndi.JndiObjectFactoryBean

10 Spring :: Integration with JNDI org.springframework.jndi.JndiTemplate: Responsible for object lookup, binding, rebinding, and unbind; Implements callback-based interface: – T execute(JndiCallback contextCallback) Example: JndiTemplate template = new JndiTemplate(); … template.bind("SomeKey", "SomeValue"); … String value = (String)template.lookup("SomeKey"); template.rebind("SomeKey", "SomeOtherValue");

11 Spring :: Integration with JNDI org.springframework.jndi.JndiCallback : For example, when you want to log JNDI operations you have to: –Create new class that will implement JndiCallback; –Move it to execute method from JndiTemplate;

12 Spring :: Integration with JNDI org.springframework.jndi.JndiCallback : JndiTemplate template = new JndiTemplate(); CustomJndiAccessForLogging callback = new CustomJndiAccessForLogging("key"); Object result = template.execute(callback); public class CustomJndiAccessForLogging implements JndiCallback { private String key; public CustomJndiAccessForLogging(String key) { this.key = key;} public Object doInContext(Context context) throws NamingException { System.out.println("Start lookup operation"); Object value = context.lookup(key); System.out.println("End lookup operation"); return value; }

13 Spring :: Integration with JNDI org.springframework.jndi.JndiObjectFactoryBean : Responsible for data retrieval from JNDI repositiry; Main strategy is to look up objects and cache them; Can be modified either declaratively or programmatically;

14 Spring :: Integration with JNDI org.springframework.jndi.JndiObjectFactoryBean : java:comp/env/welcomeMessage In InfoFromJndi bean the value for welcomeMessage field is taken from JNDI Attribute value for welcomeMessage is substituted for JndiObjectFactoryBean that gets its value from JNDI public class InfoFromJndi { String welcomeMessage; }

15 Any questions!?