spring dynamic modules by example - martin lippert · spring dynamic modules byby a p e example...
TRANSCRIPT
![Page 1: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/1.jpg)
June 10-11, 2008 Berlin, Germany
Spring Dynamic Modules by Exampleby a p e
Martin LippertGerd Wütherich
![Page 2: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/2.jpg)
Agenda• Spring
• Overview of the Spring frameworkA h t l• A short example
• Spring Dynamic Modules• Overview of Spring DMp g• A short example
• What‘s new in Spring DM 1.1W b t• Web support
• A short example
2
![Page 3: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/3.jpg)
Key Spring Concepts
SimpleObj tSimpleObjectObjectObject
Portable Service Abstractions
3
Portable Service Abstractions
![Page 4: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/4.jpg)
The Heart of Spring
• Lightweight containerF ll t k i l bj t b d li ti d l t• Full stack, simple object based application development
• Works in any environment• web-app, ejb, integration test, standalonepp, j , g ,
• Provides…• a powerful object factory that manages the instantiation,
configuration, decoration and assembly of objects
4
![Page 5: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/5.jpg)
Spring Framework
• Dependency injectionA t O i t d P i t• Aspect Oriented Programming support
• Technology abstractions• Integration with persistence technologies (JDBC Hibernate)Integration with persistence technologies (JDBC, Hibernate)• Web application support Spring MVC, JSF and Struts• Enterprise service abstractions
T ti• Transactions• Messaging• …
5
![Page 6: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/6.jpg)
Spring: An Example
• The Order Service…b d t l t k d f t• … can be used to place a stock order for a customer.
• … is accessible via RMI.
• The Customer Service…• … can be used to retrieve customer information.
6
![Page 7: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/7.jpg)
Intermediate result
• Spring simplifies the development of enterprise applicationsapplications
• “De facto standard for JEE development”De facto standard for JEE development
7
![Page 8: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/8.jpg)
Spring Dynamic Modules for OSGi Service PlatformsService Platforms • Formerly known as “Spring-OSGi”
A j t i th S i tf li• An open source project in the Spring portfolio• led by SpringSource• committers from BEA and Oracle
• http://www.springframework.org/osgi• Allows to implement Spring Applications on top of an
OSGi framework• Works with Equinox, Felix, Knopflerfish
8
![Page 9: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/9.jpg)
Project Objectives
• Bring the benefits of OSGi:d l it• modularity
• versioning• lifecycle support
• To Spring-based enterprise application development
9
![Page 10: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/10.jpg)
Challenges
• Complexity• Bring the simplicity of POJOs to OSGi• Bring the simplicity of POJOs to OSGi
• Integrate with OSGi service model• Spring beans <==> OSGi services
• Testing• Enable testing without OSGi container• No dependencies on OSGi APIsNo dependencies on OSGi APIs
• Allow people to use all the Spring technology abstractions
1010
![Page 11: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/11.jpg)
Bundles und Spring• Application context per bundle:
• Spring DM creates and destroys the application context p g y ppwhen the bundle is started or stopped
• META-INF/spring/*.xml or Spring-Context header in MANIFEST MFMANIFEST.MF
1111
![Page 12: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/12.jpg)
Beans as OSGi Services
• Spring beans can be exported as OSGi Services• (no dependencies on OSGi Service Registry API)
<bean name="customerService" class="com.wuetherich.osgi.customerservice.impl.CustomerServiceImpl"/>
<osgi:service id="customerServiceOsgi" f " t S i "
1212
ref="customerService" interface="com.wuetherich.osgi.customerservice.CustomerService"/>
![Page 13: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/13.jpg)
OSGi Services as Beans
• OSGi Services can be imported and integrated as beansp g• (again no dependencies on OSGi Service Registry API)
<osgi:reference id="customerServiceOsgi" interface="com wuetherich osgi customerservice CustomerService"/>interface= com.wuetherich.osgi.customerservice.CustomerService />
<bean id="orderService" class="com.wuetherich.osgi.orderservice.internal.OrderServiceImpl"><property name="customerService">
1313
<ref local="customerServiceOsgi"/></property>
</bean>
![Page 14: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/14.jpg)
The Spring OSGi Modell
1414
![Page 15: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/15.jpg)
Spring DM by Example
1515
![Page 16: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/16.jpg)
Further Possibilities
• Cardinality• Relationship between imported OSGi Services and theRelationship between imported OSGi Services and the
representing bean (1..1, 0..1, 1..n, 0..n)• Service Listener
• Informs about service changes• <osgi:property-placeholder>
• Refer to properties from the ConfigAdmin service• <osgi:bundle>g
• Refers to the OSGi bundle object• <osgi:virtual-bundle>
• Install a virtual OSGi bundle on the fly (testing)
16
sta a tua OSG bu d e o t e y (test g)
16
![Page 17: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/17.jpg)
Results
• No OSGi API programming necessary• Spring POJO programming modelSpring POJO programming model
• Visibilities of spring beans controllable via service exports and importsexports and imports• Dependency injection across bundles
• Dynamic service handling made easierDynamic service handling made easier
1717
![Page 18: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/18.jpg)
Spring-DM Web Support
• Focus of Spring DM 1.1• Currently under developmentCurrently under development• Integration of existing spring web support with Spring DM
• Web applications with OSGiWeb applications with OSGi• Different deployment scenarios possible
18
![Page 19: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/19.jpg)
OSGi-based web apps – part 1
• Scenario 1: OSGi embedded into web app
19
Scenario 1: OSGi embedded into web app
![Page 20: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/20.jpg)
OSGi-based web apps – part 2
• Scenario 2: Web container embedded into OSGi
20
Scenario 2: Web container embedded into OSGi
![Page 21: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/21.jpg)
The Spring DM way…
21
![Page 22: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/22.jpg)
Web applications as Bundles
• „Regular“ WAR files• Additional Bundle-Manifest
• web.xml shows how Spring DM is integrated<context-param> <param-name>contextClass</param-name> <param-value>org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext</param-value>
</ t t ></context-param>
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener
22
</listener-class> </listener>
![Page 23: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/23.jpg)
Spring DM Web Support by Example
23
![Page 24: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/24.jpg)
Even more Spring… ☺
• All the Spring features for clients as well• Eclipse-RCP, for exampleEclipse RCP, for example
• Integration with Equinox Extension Registry model possiblep• Dependency injection for extension objects, for example• http://www.martinlippert.org/
2424
![Page 25: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/25.jpg)
Outlook
• More information:• http://www.springframework.org/osgihttp://www.springframework.org/osgi• http://groups.google.com/group/spring-osgi• http://www.springframework.org/osgi/specification
• Spring Dynamic Modules tutorial:• http://www.eclipsecon.org/2008/?page=sub/&id=495
2525
![Page 26: Spring Dynamic Modules by Example - Martin Lippert · Spring Dynamic Modules byby a p e Example Martin Lippert Gerd Wütherich. Agenda • Spring ... • Web application support Spring](https://reader036.vdocument.in/reader036/viewer/2022062916/5ec9748221939034e86c7662/html5/thumbnails/26.jpg)
Die OSGi Service Platform –Eine Einführung mit Eclipse EquinoxEine Einführung mit Eclipse Equinox
• Detailed introduction into OSGi
• April 2008, dpunkt.verlag• ISBN 978-3-89864-457-0• Already available!!!• Already available!!!
• (but German only at the moment )moment…)
26