SlideShare una empresa de Scribd logo
1 de 21
Descargar para leer sin conexión
Spring framework
                     Motto: Musíte rozbít vejce když chcete udělat omeletu




                Spring framework training materials by Roman Pichlík is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

Sunday 13 May 2012                                                                                                                                       1
Java EE
                     Kurz jak používat Java EE a nezbláznit se z toho




Sunday 13 May 2012                                                      2
Co Spring nabízí
                     • EJB
                     • JMS
                     • JNDI
                     • JCA
                     • Remoting
                     • Napojení na služby

Sunday 13 May 2012                              3
EJB

                     • Zjednoduššené vytváření EJB
                      • SLSB, SLFB, MDB
                        • AbstractStatelessSessionBean
                        • AbstractStatefulSessionBean
                        • AbstractJmsMessageDrivenBean


Sunday 13 May 2012                                       4
Jak na vlastní beanu




Sunday 13 May 2012                          5
Vlastní business rozhraní


  public interface ReservationService {

  	
  	    public boolean reserveBook(Long bookId, Date from, Date to, User user);	
  	
  }




Sunday 13 May 2012                                                                6
Implementace

  @Service(value="reservationService")
  public class ReservationServiceImpl implements ReservationService {
  	
  	 @Autowired
  	 private BookService bookService;

  	    public boolean reserveBook(Long bookId, Date from, Date to, User user) {
  	    	 Book book = bookService.getBook(bookId);
  	    	 if(book == null) {
  	    	 	 throw new RuntimeException("Sorry, the book doesn't exist");
  	    	 }
  	    	 return true;
  	    }
  }




Sunday 13 May 2012                                                                7

Spring bean, mozno testovat
EJB facade




Sunday 13 May 2012                8
Vlastní fasáda
   Předek, zaručující Spring                            EJB má stejné rozhraní
           podport                                        jako Spring beana
  public class ReservationServiceEJBFacade extends
                               AbstractStatelessSessionBean implements ReservationService {
  	
  	 private static final long serialVersionUID = 1L;

  	    private ReservationService reservationService;                       Získání spring
  	    @Override                                                                beany
  	    protected void onEjbCreate() throws CreateException {
  	    	 reservationService = getBeanFactory().getBean("reservationService");	
  	    }

  	    public boolean reserveBook(Long bookId, Date from, Date to, User user) {	 	
  	    	 return reservationService.reserveBook(bookId, from, to, user);
  	    }	
  }




Sunday 13 May 2012                                                                            9

-stejny business interface nam umuznuje delegovat volani
Home a Local Interface
  import javax.ejb.CreateException;
  import javax.ejb.EJBLocalHome;

  public interface ReservationServiceHome extends EJBLocalHome {

  	    public ReservationServiceLocal create() throws CreateException;
  }




  import javax.ejb.EJBLocalObject;

  import cz.sweb.pichlik.ReservationService;

  public interface ReservationServiceLocal extends EJBLocalObject, ReservationService   {
  }




Sunday 13 May 2012                                                                          10
Jak se Spring startuje
  <ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/
  XMLSchema-instance"
  	 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-
  jar_2_1.xsd"
  	 version="2.1" id="ejb-jar_ID">
  	 <description>Book service EJB facade</description>
  	 <display-name>ejbs</display-name>                Určuje kontext, který se bude
  	 <enterprise-beans>                                         bootovat
  	 	 <session>
  	 	 	 <description>Book service EJB facade</description>
  	 	 	 <ejb-name>ReservationServiceEJBFacade</ejb-name>
  	 	 	 <local-home>cz.sweb.pichlik.ejb.ReservationServiceHome</local-home>
  	 	 	 <local>cz.sweb.pichlik.ejb.ReservationServiceLocal</local>
  	 	 	 <ejb-class>cz.sweb.pichlik.ejb.ReservationServiceEJBFacade</ejb-class>
  	 	 	 <session-type>Stateless</session-type>
  	 	 	 <transaction-type>Container</transaction-type>	    	 	
  	 	 	 <env-entry>
  	 	 	 	 <env-entry-name>ejb/BeanFactoryPath</env-entry-name>
  	 	 	 	 <env-entry-type>java.lang.String</env-entry-type>
  	 	 	 	 <env-entry-value>classpath*:META-INF/businessContext.xml</env-entry-value>
  	 	 	 </env-entry>
  	 	 </session>
Sunday 13 May 2012                                                                         11

- kazda instance beany si vytvari vlastni kontext.
JNDI




Sunday 13 May 2012          12
Lookup generic, local&remote
  <jee:jndi-lookup id="simple"
               jndi-name="jdbc/MyDataSource"
               cache="true"
               resource-ref="true"
               lookup-on-startup="false"
               expected-type=""
               proxy-interface="com.myapp.Foo"/>

  <jee:local-slsb id="complexLocalEjb"
      jndi-name="ejb/RentalServiceBean"
      business-interface="com.foo.service.RentalService"
      cache-home="true"
      lookup-home-on-startup="true"
      resource-ref="true">

  <jee:remote-slsb id="complexRemoteEjb"
      jndi-name="ejb/MyRemoteBean"
      business-interface="com.foo.service.RentalService"
      cache-home="true"
      lookup-home-on-startup="true"
      resource-ref="true"
      home-interface="com.foo.service.RentalService"
      refresh-home-on-connect-failure="true">
Sunday 13 May 2012                                         13
Remoting




Sunday 13 May 2012              14
Podporované protokoly

                     • Client/Server
                      • RMI
                      • Hessian/Burlap
                      • HttpInvoker
                      • JAX-RPC, JAX-WS


Sunday 13 May 2012                           15
HttpInvoker service
     <servlet>
                                                                        web.xml
       <servlet-name>remoting</servlet-name>
       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
     </servlet>

     <servlet-mapping>
       <servlet-name>remoting</servlet-name>
       <url-pattern>/remoting/*</url-pattern>
     </servlet-mapping>




                                        remoting-servlet.xml

  <bean name="/ReservationService"
  class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
    	 <property name="service" ref="web.reservationService"/>
       	 <property name="serviceInterface" value="cz.sweb.pichlik.ReservationService"/>
  </bean>



Sunday 13 May 2012                                                                        16
HttpInvoker client


  <bean id="client.reservationService"
  class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
     <property name="serviceUrl" value="http://localhost:8080/servlet/remoting/ReservationService"/>
     <property name="serviceInterface" value="cz.sweb.pichlik.ReservationService"/>
  </bean>




Sunday 13 May 2012                                                                                     17
JMS




Sunday 13 May 2012         18
Podporované typy


                     • MDB
                        • AbstractJmsMessageDrivenBean
                     • Spring MDB
                     • Client


Sunday 13 May 2012                                       19
Mail




Sunday 13 May 2012          20
import org.springframework.mail.SimpleMailMessage;
 import org.springframework.mail.MailSender;

 @Service
 public class EmailExample {

     @Autowired
     private MailSender mailSender;
     @Autowired
     private SimpleMailMessage templateMessage;

     public void sayHello() {
         SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
         msg.setTo(order.getCustomer().getEmailAddress());
         msg.setText(“HelloWorld”);
         this.mailSender.send(msg);
     }
 }




 <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
   <property name="host" value="mail.mycompany.com"/>
 </bean>

 <!-- this is a template message that we can pre-load with default state -->
 <bean id="templateMessage" class="org.springframework.mail.SimpleMailMessage">
   <property name="from" value="customerservice@mycompany.com"/>
   <property name="subject" value="Your order"/>
 </bean>




Sunday 13 May 2012                                                                     21
org.springframework.mail.javamail.MimeMessageHelp
er

Más contenido relacionado

Similar a Spring J2EE

GIDS 2012: Java Message Service 2.0
GIDS 2012: Java Message Service 2.0GIDS 2012: Java Message Service 2.0
GIDS 2012: Java Message Service 2.0Arun Gupta
 
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7Max Andersen
 
GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012Arun Gupta
 
Jsf2 overview
Jsf2 overviewJsf2 overview
Jsf2 overviewsohan1234
 
J2EE - Practical Overview
J2EE - Practical OverviewJ2EE - Practical Overview
J2EE - Practical OverviewSvetlin Nakov
 
Java script performance tips
Java script performance tipsJava script performance tips
Java script performance tipsShakti Shrestha
 
Enterprise Java Beans( E)
Enterprise  Java  Beans( E)Enterprise  Java  Beans( E)
Enterprise Java Beans( E)vikram singh
 
GlassFish REST Administration Backend
GlassFish REST Administration BackendGlassFish REST Administration Backend
GlassFish REST Administration BackendArun Gupta
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)vikram singh
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGESKalpana T
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2vikram singh
 
Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2vikram singh
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)vikram singh
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2vikram singh
 

Similar a Spring J2EE (20)

GIDS 2012: Java Message Service 2.0
GIDS 2012: Java Message Service 2.0GIDS 2012: Java Message Service 2.0
GIDS 2012: Java Message Service 2.0
 
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
 
GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012
 
Jsf2 overview
Jsf2 overviewJsf2 overview
Jsf2 overview
 
J2EE - Practical Overview
J2EE - Practical OverviewJ2EE - Practical Overview
J2EE - Practical Overview
 
Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)
 
J2 Ee Overview
J2 Ee OverviewJ2 Ee Overview
J2 Ee Overview
 
14 mvc
14 mvc14 mvc
14 mvc
 
EJB 3.1 and GlassFish v3 Prelude
EJB 3.1 and GlassFish v3 PreludeEJB 3.1 and GlassFish v3 Prelude
EJB 3.1 and GlassFish v3 Prelude
 
Java script performance tips
Java script performance tipsJava script performance tips
Java script performance tips
 
Enterprise Java Beans( E)
Enterprise  Java  Beans( E)Enterprise  Java  Beans( E)
Enterprise Java Beans( E)
 
GlassFish REST Administration Backend
GlassFish REST Administration BackendGlassFish REST Administration Backend
GlassFish REST Administration Backend
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)
 
10 J D B C
10  J D B C10  J D B C
10 J D B C
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGES
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2
 
Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2
 
Spring database - part2
Spring database -  part2Spring database -  part2
Spring database - part2
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2
 

Más de Roman Pichlík

MongoDB for Java Developers
MongoDB for Java DevelopersMongoDB for Java Developers
MongoDB for Java DevelopersRoman Pichlík
 
Nosql from java developer pov
Nosql from java developer povNosql from java developer pov
Nosql from java developer povRoman Pichlík
 
Spring framework - J2EE S Lidskou Tvari
Spring framework - J2EE S Lidskou TvariSpring framework - J2EE S Lidskou Tvari
Spring framework - J2EE S Lidskou TvariRoman Pichlík
 
Dependency Injection Frameworky
Dependency Injection FrameworkyDependency Injection Frameworky
Dependency Injection FrameworkyRoman Pichlík
 

Más de Roman Pichlík (9)

Spring ioc-advanced
Spring ioc-advancedSpring ioc-advanced
Spring ioc-advanced
 
Spring integration
Spring integrationSpring integration
Spring integration
 
Spring dao
Spring daoSpring dao
Spring dao
 
Spring aop
Spring aopSpring aop
Spring aop
 
Spring Web Services
Spring Web ServicesSpring Web Services
Spring Web Services
 
MongoDB for Java Developers
MongoDB for Java DevelopersMongoDB for Java Developers
MongoDB for Java Developers
 
Nosql from java developer pov
Nosql from java developer povNosql from java developer pov
Nosql from java developer pov
 
Spring framework - J2EE S Lidskou Tvari
Spring framework - J2EE S Lidskou TvariSpring framework - J2EE S Lidskou Tvari
Spring framework - J2EE S Lidskou Tvari
 
Dependency Injection Frameworky
Dependency Injection FrameworkyDependency Injection Frameworky
Dependency Injection Frameworky
 

Último

AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentationyogeshlabana357357
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsLeah Henrickson
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe中 央社
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfFIDO Alliance
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyUXDXConf
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty SecureFemke de Vroome
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераMark Opanasiuk
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfFIDO Alliance
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?Mark Billinghurst
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...panagenda
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfFIDO Alliance
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaCzechDreamin
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessUXDXConf
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIES VE
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPTiSEO AI
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024Stephen Perrenod
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024Lorenzo Miniero
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctBrainSell Technologies
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfFIDO Alliance
 

Último (20)

AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 

Spring J2EE

  • 1. Spring framework Motto: Musíte rozbít vejce když chcete udělat omeletu Spring framework training materials by Roman Pichlík is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. Sunday 13 May 2012 1
  • 2. Java EE Kurz jak používat Java EE a nezbláznit se z toho Sunday 13 May 2012 2
  • 3. Co Spring nabízí • EJB • JMS • JNDI • JCA • Remoting • Napojení na služby Sunday 13 May 2012 3
  • 4. EJB • Zjednoduššené vytváření EJB • SLSB, SLFB, MDB • AbstractStatelessSessionBean • AbstractStatefulSessionBean • AbstractJmsMessageDrivenBean Sunday 13 May 2012 4
  • 5. Jak na vlastní beanu Sunday 13 May 2012 5
  • 6. Vlastní business rozhraní public interface ReservationService { public boolean reserveBook(Long bookId, Date from, Date to, User user); } Sunday 13 May 2012 6
  • 7. Implementace @Service(value="reservationService") public class ReservationServiceImpl implements ReservationService { @Autowired private BookService bookService; public boolean reserveBook(Long bookId, Date from, Date to, User user) { Book book = bookService.getBook(bookId); if(book == null) { throw new RuntimeException("Sorry, the book doesn't exist"); } return true; } } Sunday 13 May 2012 7 Spring bean, mozno testovat
  • 8. EJB facade Sunday 13 May 2012 8
  • 9. Vlastní fasáda Předek, zaručující Spring EJB má stejné rozhraní podport jako Spring beana public class ReservationServiceEJBFacade extends AbstractStatelessSessionBean implements ReservationService { private static final long serialVersionUID = 1L; private ReservationService reservationService; Získání spring @Override beany protected void onEjbCreate() throws CreateException { reservationService = getBeanFactory().getBean("reservationService"); } public boolean reserveBook(Long bookId, Date from, Date to, User user) { return reservationService.reserveBook(bookId, from, to, user); } } Sunday 13 May 2012 9 -stejny business interface nam umuznuje delegovat volani
  • 10. Home a Local Interface import javax.ejb.CreateException; import javax.ejb.EJBLocalHome; public interface ReservationServiceHome extends EJBLocalHome { public ReservationServiceLocal create() throws CreateException; } import javax.ejb.EJBLocalObject; import cz.sweb.pichlik.ReservationService; public interface ReservationServiceLocal extends EJBLocalObject, ReservationService { } Sunday 13 May 2012 10
  • 11. Jak se Spring startuje <ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/ XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb- jar_2_1.xsd" version="2.1" id="ejb-jar_ID"> <description>Book service EJB facade</description> <display-name>ejbs</display-name> Určuje kontext, který se bude <enterprise-beans> bootovat <session> <description>Book service EJB facade</description> <ejb-name>ReservationServiceEJBFacade</ejb-name> <local-home>cz.sweb.pichlik.ejb.ReservationServiceHome</local-home> <local>cz.sweb.pichlik.ejb.ReservationServiceLocal</local> <ejb-class>cz.sweb.pichlik.ejb.ReservationServiceEJBFacade</ejb-class> <session-type>Stateless</session-type> <transaction-type>Container</transaction-type> <env-entry> <env-entry-name>ejb/BeanFactoryPath</env-entry-name> <env-entry-type>java.lang.String</env-entry-type> <env-entry-value>classpath*:META-INF/businessContext.xml</env-entry-value> </env-entry> </session> Sunday 13 May 2012 11 - kazda instance beany si vytvari vlastni kontext.
  • 13. Lookup generic, local&remote <jee:jndi-lookup id="simple" jndi-name="jdbc/MyDataSource" cache="true" resource-ref="true" lookup-on-startup="false" expected-type="" proxy-interface="com.myapp.Foo"/> <jee:local-slsb id="complexLocalEjb" jndi-name="ejb/RentalServiceBean" business-interface="com.foo.service.RentalService" cache-home="true" lookup-home-on-startup="true" resource-ref="true"> <jee:remote-slsb id="complexRemoteEjb" jndi-name="ejb/MyRemoteBean" business-interface="com.foo.service.RentalService" cache-home="true" lookup-home-on-startup="true" resource-ref="true" home-interface="com.foo.service.RentalService" refresh-home-on-connect-failure="true"> Sunday 13 May 2012 13
  • 15. Podporované protokoly • Client/Server • RMI • Hessian/Burlap • HttpInvoker • JAX-RPC, JAX-WS Sunday 13 May 2012 15
  • 16. HttpInvoker service <servlet> web.xml <servlet-name>remoting</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>remoting</servlet-name> <url-pattern>/remoting/*</url-pattern> </servlet-mapping> remoting-servlet.xml <bean name="/ReservationService" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter"> <property name="service" ref="web.reservationService"/> <property name="serviceInterface" value="cz.sweb.pichlik.ReservationService"/> </bean> Sunday 13 May 2012 16
  • 17. HttpInvoker client <bean id="client.reservationService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean"> <property name="serviceUrl" value="http://localhost:8080/servlet/remoting/ReservationService"/> <property name="serviceInterface" value="cz.sweb.pichlik.ReservationService"/> </bean> Sunday 13 May 2012 17
  • 18. JMS Sunday 13 May 2012 18
  • 19. Podporované typy • MDB • AbstractJmsMessageDrivenBean • Spring MDB • Client Sunday 13 May 2012 19
  • 21. import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.MailSender; @Service public class EmailExample { @Autowired private MailSender mailSender; @Autowired private SimpleMailMessage templateMessage; public void sayHello() { SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage); msg.setTo(order.getCustomer().getEmailAddress()); msg.setText(“HelloWorld”); this.mailSender.send(msg); } } <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> <property name="host" value="mail.mycompany.com"/> </bean> <!-- this is a template message that we can pre-load with default state --> <bean id="templateMessage" class="org.springframework.mail.SimpleMailMessage"> <property name="from" value="customerservice@mycompany.com"/> <property name="subject" value="Your order"/> </bean> Sunday 13 May 2012 21 org.springframework.mail.javamail.MimeMessageHelp er