Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
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
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
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.