SlideShare uma empresa Scribd logo
1 de 36
Baixar para ler offline
Bridging The Gap
  Integrating Spring and CDI



                       Ray Ploski
                        Director, Developer Programs & Strategy

                                  @rayploski
Protagonists


                 Spring                       Contexts & Dependency Injection
                Since 2004                                   Since 2009

    Popular Enterprise Java Framework         Standard Programming Model for Java EE 6

Conceived to provide an alternative to EJBs              Integrates with EJB

          Dependency Injection                         Dependency Injection

                   AOP                                Cross Cutting Concerns
Commonalities
• Similar Concepts

 • container - managing object
  graphs according to a developer-
  provided blueprint

 • bean - a managed object

• Both Support
 • JSR-330 (@Inject)
 • JSR-250 (Java EE 5 injection,
   Lifecycle Annotations)
Differences
                 JPA          JMS


             JDBC      JSF          JTA   CDI


                 JSP          EJB




                             Spring

•Implicit (CDI) vs. explicit (Spring) blueprint
Seam-Spring Module
    A utility library for integrating
Spring and CDI programming models

         Enables the use of
     Java business components
       across technology lines
Seam 3 Spring Module


• Seam3 - a library of CDI extensions

• Similar functionality to the Seam 2 Spring integration
 • With CDI specific undertones

• Will merge into Apache DeltaSpike
Seam 3 Spring Module


• Seam3 - a library of CDI extensions

• Similar functionality to the Seam 2 Spring integration
 • With CDI specific undertones

• Will merge into Apache DeltaSpike

         +              +   CDISource              DeltaSpike
Seam 3 Modules

               •   Mail
•   Solder
               •   Validation
•   Config
               •   Wicket
•   Social
               •   Catch
•   JMS
               •   Remoting
•   JCR                         Drools   SwitchYard
               •   REST
•   Security
               •   Faces        jBPM        Errai
•   I18N
               •   Spring        TBD      Ecetera
Seam 3 Modules

                                 DeltaSpike
               •   Mail
•   Solder
               •   Validation
•   Config
               •   Wicket
•   Social
               •   Catch          Various JBoss
•   JMS                             Projects
               •   Remoting
•   JCR                         Drools   SwitchYard
               •   REST
•   Security
               •   Faces        jBPM        Errai
•   I18N
               •   Spring        TBD      Ecetera
Seam3 Spring Module
         Design Goals

• Minimize changes to existing code

• Non-intrusive approach

• Highly customizable

• Mirror similar capabilities
Why?
• Reuse existing investments

• Integrate groups with various expertise

• Simplify integration of Spring and Java EE

• Ease migration of legacy Spring apps to
 Java EE 6
Seam 3 Spring Module Features
• Integrating Spring components
  into CDI

 • Accessing Spring
    ApplicationContexts

   • created by the extension
                                     -or-
   • access AC’s created by Spring
      components (e.g. web
      ApplicationContext)

• Accessing CDI beans
 • exposing Spring beans as CDI
    beans
Integrating Spring into CDI
   1.) Get the ApplicationContext
Integrating Spring components into CDI



  Managed                        Managed   • Implemented as a Standard CDI
   Bean        Managed            Bean       Extension
                Bean
                                           • Spring contexts and Spring beans
                                             are installed as CDI beans
  • ApplicationContexts
                                           • Implemented using the resource
  • Spring Beans                             producer pattern
      * Can be bootstrapped or external
ApplicationContext Management

   Spring contexts are exposed as CDI beans


                          	   @Produces @Web @SpringContext
                                ApplicationContext context;

Created by Seam                     Created by Spring
 Spring Module
                     - or -
 - @Producer fields                      e.g. a Web
 - SPI Based                       ApplicationContext
@SpringContext Annotation

1.) Bootstrapped By Spring- CDI Extension



 	 @Produces @SpringContext
 	 @ApplicationScoped
 	 @Configuration
   (locations={"classpath:springCtx.xml"})
 	 ApplicationContext springContext;
@SpringContext Annotation

2.) Used within a CDI Managed Bean




 	 //Usage
 	 @Inject @SpringContext
 	 ApplicationContext context;
@SpringContext Annotation

1.) Web Application Context (external)



 // Spring Application Context loaded by
 // Servlet container

 @Produces @Web @SpringContext
   ApplicationContext context;
Integrating Spring into CDI
  2.) Get access to the Spring Beans
@SpringContext Annotation

2.) Use within a CDI Managed Bean




 	 //Usage
 	 @Inject @SpringContext
 	 ApplicationContext context;
Spring Bean Producer
Apply the resource producer pattern for creating
Spring ApplicationContext CDI beans


@Produces @SpringBean
	 UserService userService;



//Usage
@SessionScoped
public class AllocationManager {
	 @Inject
	 UserService userService;
}
Avoiding Bean Duplication
•Imported Spring beans may cause duplication issues
 • CDI will add any classes automatically as beans
 • Extension-added beans will be in conflict

•Options:
 • Solder @Veto annotation (recommended)
 • Using side-effects of @Typed and @Alternative
  (standard-based but we do not recommend)

• Proprietary extensions for bean scanning (e.g. Weld)
Bean Duplication and Vetoing

                      Importing beans may
                      result in duplication ...




... but vetoing can
solve this problem
In-Extension Context Bootstrapping
  •Alternative to @Produces @SpringContext
   @Configuration

  •Advantages relative to CDI lifecycle
   • Spring context is bootstrapped before
    bean discovery
   • Spring bean classes are automatically
    vetoed
Integrating CDI into Spring
CDI integration into Spring

• Uses standard Spring mechanisms
 • BeanFactories
 • BeanPostProcessors/BeanFactoryPostProcessors

• Most facilities are hidden behind the <cdi:*/>
 namespace
Accessing the Bean Manager


          <cdi:bean-manager/>




         •Usage:
          @Autowired BeanManager beanManager;

xmlns:cdi="http://www.jboss.org/schema/seam/spring"
Accessing CDI Beans

        	<cdi:bean-reference id="user" type="example.User">
               <cdi:qualifier type="example.BusinessUser"/>
       	 </cdi:bean-reference>


       	 @Component 
       	 public class User {

       	     @Autowired User user;

       	 }

xmlns:cdi="http://www.jboss.org/schema/seam/spring"
Importing CDI Beans into Spring
Scoping
•Spring and CDI have different approaches to bean scoping
 • Spring - singletons, application-scoped
 • CDI - prototype, 'default-scoped'

•The module preserves the original scope
 • @SpringContext beans are @ApplicationScoped 

 • @SpringBean are default-scoped and fall back to the native Spring
  scope (AOP scope proxy required)

 • CDI beans are prototype-scoped and fall back to the native CDI
  scope (through their scoped proxy) 
Beyond CDI

•This module can serve as basis
 for integrating any Java EE
 component with Spring
 • EJBs
 • JAX-RS 
 • any component that
   understands CDI
Roadmap

• Current version: 3.1.0.Final (included in Seam 3.1.0.Final)
• Upcoming versions:
  o 3.1.x - minor features, bug fixes

 o   3.2.x (March/April 2012) - additional features
      bean autoimport
      eventing bridge
      bridging Spring AOP/CDI interceptors,decorators
      Seam Persistence integration (transactions, Persistence Contexts)

• Post 3.2
  o integration into Apache DeltaSpike
ENTERPRISE APPLICATION
               PLATFORM
               6.0


JBoss AS 7.1
SUBSCRIPTIONS = DEVELOPER PRODUCTIVITY
                                      Frees you to focus on the new stuff


  NOT JUST FOR ADMINS



“Q: I’m writing a WS-Policy and...”


                                                    A C C E L E R AT E
       KILL                                         YOUR PROJECT!
       DRUDGERY

                                      Fight your bugs, not others’
                                                                           33
                                        http://www.redhat.com/jboss/benefits/
Thank You!
             Seam 3 Spring Module - http://bit.ly/Seam3Spring

         Example Code - http://bit.ly/JUDConSeamSpringCode

                    Apache DeltaSpike - http://bit.ly/zsWz2x

Ray Ploski
Director, Developer Programs & Strategy


    @rayploski

Mais conteúdo relacionado

Mais procurados

Spring 4 on Java 8 by Juergen Hoeller
Spring 4 on Java 8 by Juergen HoellerSpring 4 on Java 8 by Juergen Hoeller
Spring 4 on Java 8 by Juergen HoellerZeroTurnaround
 
Microservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloudMicroservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloudBen Wilcock
 
Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud Shekhar Gulati
 
Spring introduction
Spring introductionSpring introduction
Spring introductionManav Prasad
 
Developing modern java web applications with java ee 7 and angular js
Developing modern java web applications with java ee 7 and angular jsDeveloping modern java web applications with java ee 7 and angular js
Developing modern java web applications with java ee 7 and angular jsShekhar Gulati
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 
Java EE 8 Update
Java EE 8 UpdateJava EE 8 Update
Java EE 8 UpdateRyan Cuprak
 
Android MvRx Framework 介紹
Android MvRx Framework 介紹Android MvRx Framework 介紹
Android MvRx Framework 介紹Kros Huang
 
Apache DeltaSpike
Apache DeltaSpikeApache DeltaSpike
Apache DeltaSpikeos890
 
Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Ryan Cuprak
 
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013Sam Brannen
 
Jdc 2010 - Maven, Intelligent Projects
Jdc 2010 - Maven, Intelligent ProjectsJdc 2010 - Maven, Intelligent Projects
Jdc 2010 - Maven, Intelligent ProjectsMert Çalışkan
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action Alex Movila
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with GradleRyan Cuprak
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeansRyan Cuprak
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulMert Çalışkan
 

Mais procurados (19)

Spring 4 on Java 8 by Juergen Hoeller
Spring 4 on Java 8 by Juergen HoellerSpring 4 on Java 8 by Juergen Hoeller
Spring 4 on Java 8 by Juergen Hoeller
 
Microservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloudMicroservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloud
 
Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud
 
Java Concurrent
Java ConcurrentJava Concurrent
Java Concurrent
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
 
Developing modern java web applications with java ee 7 and angular js
Developing modern java web applications with java ee 7 and angular jsDeveloping modern java web applications with java ee 7 and angular js
Developing modern java web applications with java ee 7 and angular js
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Java EE 8 Update
Java EE 8 UpdateJava EE 8 Update
Java EE 8 Update
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Android MvRx Framework 介紹
Android MvRx Framework 介紹Android MvRx Framework 介紹
Android MvRx Framework 介紹
 
Apache DeltaSpike
Apache DeltaSpikeApache DeltaSpike
Apache DeltaSpike
 
Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]
 
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
 
Jdc 2010 - Maven, Intelligent Projects
Jdc 2010 - Maven, Intelligent ProjectsJdc 2010 - Maven, Intelligent Projects
Jdc 2010 - Maven, Intelligent Projects
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
 

Semelhante a Spring - CDI Interop

CDI Best Practices with Real-Life Examples - TUT3287
CDI Best Practices with Real-Life Examples - TUT3287CDI Best Practices with Real-Life Examples - TUT3287
CDI Best Practices with Real-Life Examples - TUT3287Ahmad Gohar
 
스프링 프레임워크
스프링 프레임워크스프링 프레임워크
스프링 프레임워크Yoonki Chang
 
Java spring framework
Java spring frameworkJava spring framework
Java spring frameworkRajiv Gupta
 
Developing modular Java applications
Developing modular Java applicationsDeveloping modular Java applications
Developing modular Java applicationsJulien Dubois
 
Codestrong 2012 breakout session how to develop your own modules
Codestrong 2012 breakout session   how to develop your own modulesCodestrong 2012 breakout session   how to develop your own modules
Codestrong 2012 breakout session how to develop your own modulesAxway Appcelerator
 
Introduction to Module Development with Appcelerator Titanium
Introduction to Module Development with Appcelerator TitaniumIntroduction to Module Development with Appcelerator Titanium
Introduction to Module Development with Appcelerator TitaniumAaron Saunders
 
AngularJS - Architecture decisions in a large project 
AngularJS - Architecture decisionsin a large project AngularJS - Architecture decisionsin a large project 
AngularJS - Architecture decisions in a large project Elad Hirsch
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework Serhat Can
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring FrameworkASG
 
Spring Framework Presantation Part 1-Core
Spring Framework Presantation Part 1-CoreSpring Framework Presantation Part 1-Core
Spring Framework Presantation Part 1-CoreDonald Lika
 
Introduction to Spring
Introduction to SpringIntroduction to Spring
Introduction to SpringSujit Kumar
 
S2GX 2012 - Introduction to Spring Integration and Spring Batch
S2GX 2012 - Introduction to Spring Integration and Spring BatchS2GX 2012 - Introduction to Spring Integration and Spring Batch
S2GX 2012 - Introduction to Spring Integration and Spring BatchGunnar Hillert
 
Spring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsSpring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsmichaelaaron25322
 
LEARNING  iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
LEARNING	 iPAD STORYBOARDS IN OBJ-­‐C LESSON 1LEARNING	 iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
LEARNING  iPAD STORYBOARDS IN OBJ-­‐C LESSON 1Rich Helton
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking TourJoshua Long
 
springtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfspringtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfBruceLee275640
 

Semelhante a Spring - CDI Interop (20)

CDI Best Practices with Real-Life Examples - TUT3287
CDI Best Practices with Real-Life Examples - TUT3287CDI Best Practices with Real-Life Examples - TUT3287
CDI Best Practices with Real-Life Examples - TUT3287
 
스프링 프레임워크
스프링 프레임워크스프링 프레임워크
스프링 프레임워크
 
Dependency Injection Styles
Dependency Injection StylesDependency Injection Styles
Dependency Injection Styles
 
Java Spring
Java SpringJava Spring
Java Spring
 
Java spring framework
Java spring frameworkJava spring framework
Java spring framework
 
Developing modular Java applications
Developing modular Java applicationsDeveloping modular Java applications
Developing modular Java applications
 
Spring session
Spring sessionSpring session
Spring session
 
Codestrong 2012 breakout session how to develop your own modules
Codestrong 2012 breakout session   how to develop your own modulesCodestrong 2012 breakout session   how to develop your own modules
Codestrong 2012 breakout session how to develop your own modules
 
Introduction to Module Development with Appcelerator Titanium
Introduction to Module Development with Appcelerator TitaniumIntroduction to Module Development with Appcelerator Titanium
Introduction to Module Development with Appcelerator Titanium
 
AngularJS - Architecture decisions in a large project 
AngularJS - Architecture decisionsin a large project AngularJS - Architecture decisionsin a large project 
AngularJS - Architecture decisions in a large project 
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Hybernat and structs, spring classes in mumbai
Hybernat and structs, spring classes in mumbaiHybernat and structs, spring classes in mumbai
Hybernat and structs, spring classes in mumbai
 
Spring Framework Presantation Part 1-Core
Spring Framework Presantation Part 1-CoreSpring Framework Presantation Part 1-Core
Spring Framework Presantation Part 1-Core
 
Introduction to Spring
Introduction to SpringIntroduction to Spring
Introduction to Spring
 
S2GX 2012 - Introduction to Spring Integration and Spring Batch
S2GX 2012 - Introduction to Spring Integration and Spring BatchS2GX 2012 - Introduction to Spring Integration and Spring Batch
S2GX 2012 - Introduction to Spring Integration and Spring Batch
 
Spring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsSpring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applications
 
LEARNING  iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
LEARNING	 iPAD STORYBOARDS IN OBJ-­‐C LESSON 1LEARNING	 iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
LEARNING  iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking Tour
 
springtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfspringtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdf
 

Último

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 

Último (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 

Spring - CDI Interop

  • 1.
  • 2. Bridging The Gap Integrating Spring and CDI Ray Ploski Director, Developer Programs & Strategy @rayploski
  • 3. Protagonists Spring Contexts & Dependency Injection Since 2004 Since 2009 Popular Enterprise Java Framework Standard Programming Model for Java EE 6 Conceived to provide an alternative to EJBs Integrates with EJB Dependency Injection Dependency Injection AOP Cross Cutting Concerns
  • 4. Commonalities • Similar Concepts • container - managing object graphs according to a developer- provided blueprint • bean - a managed object • Both Support • JSR-330 (@Inject) • JSR-250 (Java EE 5 injection, Lifecycle Annotations)
  • 5. Differences JPA JMS JDBC JSF JTA CDI JSP EJB Spring •Implicit (CDI) vs. explicit (Spring) blueprint
  • 6. Seam-Spring Module A utility library for integrating Spring and CDI programming models Enables the use of Java business components across technology lines
  • 7. Seam 3 Spring Module • Seam3 - a library of CDI extensions • Similar functionality to the Seam 2 Spring integration • With CDI specific undertones • Will merge into Apache DeltaSpike
  • 8. Seam 3 Spring Module • Seam3 - a library of CDI extensions • Similar functionality to the Seam 2 Spring integration • With CDI specific undertones • Will merge into Apache DeltaSpike + + CDISource DeltaSpike
  • 9. Seam 3 Modules • Mail • Solder • Validation • Config • Wicket • Social • Catch • JMS • Remoting • JCR Drools SwitchYard • REST • Security • Faces jBPM Errai • I18N • Spring TBD Ecetera
  • 10. Seam 3 Modules DeltaSpike • Mail • Solder • Validation • Config • Wicket • Social • Catch Various JBoss • JMS Projects • Remoting • JCR Drools SwitchYard • REST • Security • Faces jBPM Errai • I18N • Spring TBD Ecetera
  • 11. Seam3 Spring Module Design Goals • Minimize changes to existing code • Non-intrusive approach • Highly customizable • Mirror similar capabilities
  • 12. Why? • Reuse existing investments • Integrate groups with various expertise • Simplify integration of Spring and Java EE • Ease migration of legacy Spring apps to Java EE 6
  • 13. Seam 3 Spring Module Features • Integrating Spring components into CDI • Accessing Spring ApplicationContexts • created by the extension -or- • access AC’s created by Spring components (e.g. web ApplicationContext) • Accessing CDI beans • exposing Spring beans as CDI beans
  • 14. Integrating Spring into CDI 1.) Get the ApplicationContext
  • 15. Integrating Spring components into CDI Managed Managed • Implemented as a Standard CDI Bean Managed Bean Extension Bean • Spring contexts and Spring beans are installed as CDI beans • ApplicationContexts • Implemented using the resource • Spring Beans producer pattern * Can be bootstrapped or external
  • 16. ApplicationContext Management Spring contexts are exposed as CDI beans @Produces @Web @SpringContext ApplicationContext context; Created by Seam Created by Spring Spring Module - or - - @Producer fields e.g. a Web - SPI Based ApplicationContext
  • 17. @SpringContext Annotation 1.) Bootstrapped By Spring- CDI Extension @Produces @SpringContext @ApplicationScoped @Configuration (locations={"classpath:springCtx.xml"}) ApplicationContext springContext;
  • 18. @SpringContext Annotation 2.) Used within a CDI Managed Bean //Usage @Inject @SpringContext ApplicationContext context;
  • 19. @SpringContext Annotation 1.) Web Application Context (external) // Spring Application Context loaded by // Servlet container @Produces @Web @SpringContext ApplicationContext context;
  • 20. Integrating Spring into CDI 2.) Get access to the Spring Beans
  • 21. @SpringContext Annotation 2.) Use within a CDI Managed Bean //Usage @Inject @SpringContext ApplicationContext context;
  • 22. Spring Bean Producer Apply the resource producer pattern for creating Spring ApplicationContext CDI beans @Produces @SpringBean UserService userService; //Usage @SessionScoped public class AllocationManager { @Inject UserService userService; }
  • 23. Avoiding Bean Duplication •Imported Spring beans may cause duplication issues • CDI will add any classes automatically as beans • Extension-added beans will be in conflict •Options: • Solder @Veto annotation (recommended) • Using side-effects of @Typed and @Alternative (standard-based but we do not recommend) • Proprietary extensions for bean scanning (e.g. Weld)
  • 24. Bean Duplication and Vetoing Importing beans may result in duplication ... ... but vetoing can solve this problem
  • 25. In-Extension Context Bootstrapping •Alternative to @Produces @SpringContext @Configuration •Advantages relative to CDI lifecycle • Spring context is bootstrapped before bean discovery • Spring bean classes are automatically vetoed
  • 27. CDI integration into Spring • Uses standard Spring mechanisms • BeanFactories • BeanPostProcessors/BeanFactoryPostProcessors • Most facilities are hidden behind the <cdi:*/> namespace
  • 28. Accessing the Bean Manager    <cdi:bean-manager/> •Usage: @Autowired BeanManager beanManager; xmlns:cdi="http://www.jboss.org/schema/seam/spring"
  • 29. Accessing CDI Beans <cdi:bean-reference id="user" type="example.User">         <cdi:qualifier type="example.BusinessUser"/> </cdi:bean-reference> @Component  public class User { @Autowired User user; } xmlns:cdi="http://www.jboss.org/schema/seam/spring"
  • 30. Importing CDI Beans into Spring
  • 31. Scoping •Spring and CDI have different approaches to bean scoping • Spring - singletons, application-scoped • CDI - prototype, 'default-scoped' •The module preserves the original scope • @SpringContext beans are @ApplicationScoped  • @SpringBean are default-scoped and fall back to the native Spring scope (AOP scope proxy required) • CDI beans are prototype-scoped and fall back to the native CDI scope (through their scoped proxy) 
  • 32. Beyond CDI •This module can serve as basis for integrating any Java EE component with Spring • EJBs • JAX-RS  • any component that understands CDI
  • 33. Roadmap • Current version: 3.1.0.Final (included in Seam 3.1.0.Final) • Upcoming versions: o 3.1.x - minor features, bug fixes o 3.2.x (March/April 2012) - additional features  bean autoimport  eventing bridge  bridging Spring AOP/CDI interceptors,decorators  Seam Persistence integration (transactions, Persistence Contexts) • Post 3.2 o integration into Apache DeltaSpike
  • 34. ENTERPRISE APPLICATION PLATFORM 6.0 JBoss AS 7.1
  • 35. SUBSCRIPTIONS = DEVELOPER PRODUCTIVITY Frees you to focus on the new stuff NOT JUST FOR ADMINS “Q: I’m writing a WS-Policy and...” A C C E L E R AT E KILL YOUR PROJECT! DRUDGERY Fight your bugs, not others’ 33 http://www.redhat.com/jboss/benefits/
  • 36. Thank You! Seam 3 Spring Module - http://bit.ly/Seam3Spring Example Code - http://bit.ly/JUDConSeamSpringCode Apache DeltaSpike - http://bit.ly/zsWz2x Ray Ploski Director, Developer Programs & Strategy @rayploski