Download presentation
Presentation is loading. Please wait.
Published byReynold West Modified over 9 years ago
1
Spring and DWR Frameworks for Rich Web Enterprise Application Thomas Wiradikusuma thomas@wiradikusuma.com www.wiradikusuma.com Presentation to the 20 th Java User Group Meet Up (JaMU), May 20, 2006
2
Objective To introduce Spring, an application framework for developing enterprise applications. To introduce DWR, an Ajax framework for developing Rich Internet Application (RIA). To show Spring+DWR integration to get the best of both worlds.
3
Agenda Intro to Spring Spring wiring Spring step-by-step Intro to DWR DWR configuration DWR step-by-step Spring and DWR integration
4
Typical JavaEE App Development Usually developing web applications that serve many users and access (possibly many, heterogeneous) enterprise resources. EJB is used because we want some of its features. EJB is complicated, for a reason. Testing is tedious. Is there an easier way?
5
Here Comes Spring! An open source Java/JavaEE application framework. Codes originally came from Rod Johnson’s book “Expert One-on- One: J2EE Design and Development”, Wrox Press, 2002. Enables POJOs to achieve things that were previously only possible with EJBs.
6
Spring Mission Statement JavaEE should be easier to use. OO design is more important than any implementation technology, such as JavaEE. Testability is essential, and a framework such as Spring should help make your code easier to test. Spring should not compete with good existing solutions (Hibernate, Struts, etc), but should foster integration.
7
Spring Described Lightweight Inversion of control Aspect-oriented Container Framework
8
Spring Modules
9
Some Spring Usage Scenarios
10
Some Spring Usage Scenarios - 2
11
Inversion of Control Dependency injection –Beans define their dependencies through constructor arguments or properties –The container provides the injection at runtime “Don’t talk to strangers,” also known as the Hollywood principle, “Don’t call me I’ll call you.” Decouples object creators and locators from application logic Easy to maintain and reuse Testing is easier
12
Spring Bean Definition The bean class is the actual implementation of the bean being described by the BeanFactory. Bean examples: DAO, DataSource, Transaction Manager, Persistence Manager, Service objects, etc. Spring config contains implementation classes while your code should program to interfaces. Bean behaviors include: –Singleton or prototype –Autowiring –Spring-aware interfaces –Initialization and destruction methods init-method destroy-method Beans can be configured to have property values set. Can read simple values, collections, maps, references to other beans, etc.
13
Simple Spring Bean Example 10 public class OrderBeanImpl implements OrderBean { //... public void setMaxOrder(double maxOrder){ this.maxOrder = maxOrder; } public void setOrderDAO(OrderDAO orderDAO){ this.orderDAO = orderDAO; } //... }
14
Spring BeanFactory BeanFactory is core to the Spring framework –Lightweight container that loads bean definitions and manages your beans. –Configured declaratively using an XML file, or files, that determine how beans can be referenced and wired together. –Knows how to serve and manage a singleton or prototype defined bean –Responsible for lifecycle methods. –Injects dependencies into defined beans when served Avoids the use of singletons and factories
15
Spring ApplicationContext A Spring ApplicationContext allows you to get access to the objects that are configured in a BeanFactory in a framework manner. ApplicationContext extends BeanFactory –Adds services such as international messaging capabilities. –Add the ability to load file resources in a generic fashion. Several ways to configure a context: –XMLWebApplicationContext – Configuration for a web application. –ClassPathXMLApplicationContext – standalone XML application context –FileSystemXmlApplicationContext Allows you to avoid writing Service Locators
16
XMLWebApplicationContext contextConfigLocation /WEB-INF/applicationContext.xml org.springframework.web.context.ContextLoaderList ener
17
Spring MVC
18
Sample Spring Application DEMO ApplicationContext factory = new ClassPathXmlApplicationContext(“config.xml"); index.jsp Spring Bind Tag
19
Web is All Around History of dynamic web applications Web 2.0 and Ajax The DWR approach to Ajax Tools and widgets
20
Ajax – Not a Football Team Not one technology, several technologies: –XHTML and CSS –Document Object Model (DOM) –XML (and XSLT) –XMLHttpRequest (XHR) –JavaScript
21
Ajax Approach to Web
22
Ajax Approach to Web - 2
23
Issues in Ajax Browser incompatibilities Back button and browser history Working with XML in JavaScript Accessibility
24
Ajax Frameworks DWR Echo2 JSON-RPC Sajax Many more… Why DWR? –Mostly used framework –Integrates best with Spring
25
DWR Described Open source Java library Allows code in a web browser to use Java functions running on a web server as if it was in the browser Two main parts: –Java Servlet –JavaScript Dynamically generates JavaScript code based on Java classes
26
Sample DWR Configuration web.xml: dwr-invoker uk.ltd.getahead.dwr.DWRServlet debug true dwr-invoker /dwr/*
27
Sample DWR Configuration - 2 dwr.xml:
28
DWR Step-by-step 1.Install the DWR JAR file 2.Edit the config files 3.Go to the following URL: http://localhost:8080/[YOUR-WEBAPP]/dwr/ 4.Put this in your JSP:
29
Spring+DWR Integration Check list: 1.Use the latest DWR. The Spring creator has changed so it is well worth checking that you have the latest download. 2.Make sure DWR and Spring each are working OK in your application. 3.Configure DWR to work with Spring. 4.Check result in the debug pages: http://localhost:8080/[YOUR- WEBAPP]/dwr/
30
Spring+DWR Integration - 2 The SpringCreator: Find the Spring configuration: –ContextLoaderListener contextConfigLocation /WEB-INF/classes/beans.xml org.springframework.web.context.ContextLoaderLi stener –Or by “location*” parameters –Or by setting the BeanFactory Directly SpringCreator.setOverrideBeanFactory(BeanFactory)
31
Resources Spring Website: www.springframework.org The Spring Reference Manual. Walls, Craig and Ryan Breidenbach. Spring in Action. Manning. 2003. Johnson, Rod and Jurgen Hoeller. J2EE without EJB. Wrox. 2004. DWR Website: http://www.getahead.ltd.uk/dwr
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.