+ All Categories
Home > Documents > The Spring Framework J2EE without EJB

The Spring Framework J2EE without EJB

Date post: 31-Dec-2015
Category:
Upload: karen-lucas
View: 38 times
Download: 2 times
Share this document with a friend
Description:
The Spring Framework J2EE without EJB. Jürgen Höller http://www.springframework.com [email protected]. Agenda. J2EE Reviewed Introducing the Spring Framework Spring and J2EE Core Container AOP Framework Transactions & Data Access Remoting Further Services. J2EE Reviewed (1). - PowerPoint PPT Presentation
24
The Spring Framework The Spring Framework J2EE without EJB J2EE without EJB Jürgen Höller http://www.springframework.co m [email protected]
Transcript
Page 1: The Spring Framework J2EE without EJB

The Spring FrameworkThe Spring FrameworkJ2EE without EJBJ2EE without EJB

Jürgen Höllerhttp://www.springframework.com

[email protected]

Page 2: The Spring Framework J2EE without EJB

AgendaAgenda

J2EE Reviewed Introducing the Spring Framework Spring and J2EE Core Container AOP Framework Transactions & Data Access Remoting Further Services

Page 3: The Spring Framework J2EE without EJB

J2EE Reviewed (1)J2EE Reviewed (1)

Challenges of modern server-side software development▫ multi-threaded execution▫ resource and transaction management▫ remote service access▫ HTTP server integration

Java 2 Enterprise Edition (J2EE tm)▫ set of specifications for standard application

server infrastructure▫ industry standard: backed by Sun, IBM, Oracle▫ application server implements standard APIs▫ application uses standard APIs

Page 4: The Spring Framework J2EE without EJB

J2EE Reviewed (2)J2EE Reviewed (2)

J2EE specifies system services▫ Servlets, JSP, JTA, JDBC, JMS, JavaMail▫ builds on underlying standard Java runtime

J2EE also specifies component models▫ Servlets for HTTP endpoints▫ EJBs for middle tier components

Focus on traditional 3-tier server layout▫ focus on physical separation between tiers▫ middle tier always requires application server

Low-level APIs▫ direct usage in applications often cumbersome▫ comfortable high-level APIs?

Page 5: The Spring Framework J2EE without EJB

J2EE Reviewed (3)J2EE Reviewed (3)

Scope of J2EE is limited▫ EJBs are coarse-grained components

• mainly for (remote) service façades• special deployment effort for every component

▫ How to deal with fine-grained,co-located application objects?

• forced to use custom solutions• common: open source libraries / frameworks

How to run outside of an application server?▫ not covered by traditional J2EE▫ important for unit tests and integration tests▫ also important for productive development

Page 6: The Spring Framework J2EE without EJB

Spring Framework (1)Spring Framework (1)

Java / J2EE Application Framework▫ based on Rod Johnson’s book

“J2EE Design & Development” (Wiley, 2002)▫ current book: "J2EE Development without EJB"

(Rod Johnson, Jürgen Höller; Wiley, 2004) Focus on "Plain Old Java Objects" (POJOs)

▫ natural, generic component model for applications▫ flexible alternative to EJB, not tied to J2EE

Open Source Project on SourceForge▫ Apache license▫ since February 2003▫ 25 developers

Page 7: The Spring Framework J2EE without EJB

Spring Framework (2)Spring Framework (2)

Business objects as decoupled POJOs▫ configuration and wiring through framework

• or usage as normal Java objects

▫ independent from the actual environment• no unnecessary ties to a framework

▫ reusable in any kind of environment• in particular: testability in unit / integration tests

Generic middleware services▫ e.g. declarative transactions for POJOs

• flexible alternative to EJB CMT

▫ for all applications, including standalone• leverage J2EE container services when available

Page 8: The Spring Framework J2EE without EJB

Spring Framework (3)Spring Framework (3)

Integration with existing solutions▫ Object/Relational Mapping tools▫ web frameworks▫ remoting protocols

"It‘s all about choice"▫ JDBC, Hibernate, JDO, Oracle TopLink,

Apache OJB, iBATIS SQL Maps▫ Spring Web MVC, Spring Web Flow,

Struts, WebWork, Tapestry, JSF▫ HTTP invoker, RMI invoker, conventional RMI,

JAX-RPC (WSDL/SOAP), Hessian, Burlap

Page 9: The Spring Framework J2EE without EJB

Spring and J2EE (1)Spring and J2EE (1)

J2EE provides standard system services▫ to be leveraged by higher-level components▫ Spring abstractions can run on top of J2EE

J2EE system servicesJ2EE deployment and management

Spring application containerSpring service abstractions

Application components

Page 10: The Spring Framework J2EE without EJB

Spring and J2EE (2)Spring and J2EE (2)

Spring is a de-facto standard Java / J2EE application framework▫ typically running on top of J2EE server▫ but: application components are not tied to J2EE

Most popular "lightweight container"▫ widespread adoption over the past 2.5 years▫ endorsed / supported by BEA, IBM, Oracle

• e.g.: support partnership for Spring on WebLogic

EJB3 specification will follow Spring model▫ adopts some important ideas from Spring

Page 11: The Spring Framework J2EE without EJB

Spring and J2EE (3)Spring and J2EE (3)

Constantly increasing download numbers▫ ~30.000 downloads of every point release▫ >400.000 downloads overall

Growing Spring ecosystem▫ Spring sister projects

• Acegi Security, Spring Web Flow

▫ used or supported by many other products• open source and commercial• e.g. Atlassian Confluence, Liferay Portal

▫ 5 dedicated books on Spring already available• by various authors• more books in the works

Page 12: The Spring Framework J2EE without EJB

Core Container (1)Core Container (1)

"Inversion of Control"▫ configuration and lifecycle of application objects▫ objects do not configure themselves, but get

configured from the outside▫ objects don't know the origin of their configuration

"Dependency Injection"▫ "setter-based" (JavaBean properties)▫ "constructor-based" (constructor arguments)▫ alternative: "Service Lookup"

• for example: JNDI

Page 13: The Spring Framework J2EE without EJB

Core Container (2)Core Container (2)

Fine-grained externalized configuration▫ representing the internal structure of the application

• references to other components• configuration parameters

▫ enables flexible configuration management• at fine-grained component level• switching between different deployment scenarios

XML bean definitions▫ most common configuration format▫ often: separate admin properties file

• linked into XML bean definitions through placeholders

Page 14: The Spring Framework J2EE without EJB

Core Container (3)Core Container (3)

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">

<property name="driverClassName" value="${jdbc.driver}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/>

</bean>

<bean id="itemDao" class="org.springframework.samples.jpetstore.dao.ibatis.SqlMapItemDao">

<property name="dataSource" ref="dataSource"/> <property name="sqlMap" ref="sqlMap"/>

</bean>

<bean id="petStore"class="org.springframework.samples.jpetstore.domain.logic.PetStoreImpl">

<property name="orderDao" ref="orderDao"/> <property name="itemDao" ref="itemDao"/>

</bean>

Page 15: The Spring Framework J2EE without EJB

AOP Framework (1)AOP Framework (1)

"Aspect-Oriented Programming"▫ proxies for arbitrary POJOs▫ flexible combination of interceptors▫ no fixed component model ("EJB a la carte")

"Cross-Cutting Concerns"▫ actions at the beginning/end of a method call

Target methodCaller

intercept

Page 16: The Spring Framework J2EE without EJB

AOP Framework (2)AOP Framework (2)

Do not repeat code: factor out interceptor▫ e.g. logging: configurable trace log▫ e.g. security: authorization checks▫ e.g. common exception handling▫ e.g. transaction demarcation

Method interceptor▫ interceptor can be applied to any methods▫ interceptor can be enabled/disabled▫ AOP Alliance: MethodInterceptor interface▫ reuse of pre-built interceptors

Page 17: The Spring Framework J2EE without EJB

Transactions & DAOs (1)Transactions & DAOs (1)

Transaction Strategy Abstraction▫ PlatformTransactionManager SPI▫ switching between JTA and native transactions

Transaction Demarcation Options▫ programmatic demarcation a la JTA▫ declarative demarcation for arbitrary POJOs

Transaction Definitions▫ all EJB CMT propagation codes supported

• REQUIRED, REQUIRES_NEW, etc

▫ optional transaction semantics beyond EJB• nested, isolation level, timeout, read-only flag

Page 18: The Spring Framework J2EE without EJB

Transactions & DAOs (2)Transactions & DAOs (2)

DataAccessException hierarchy▫ independent of JDBC, Hibernate, JDO, etc▫ unchecked, as most failures are not recoverable▫ subclasses like OptimisticLockingFailureException

Support for DAO implementations▫ implicit access to resources▫ many operations become one-liners▫ no try/catch blocks anymore

Pre-built integration classes for many solutions▫ JDBC: JdbcTemplate▫ Hibernate: HibernateTemplate

Page 19: The Spring Framework J2EE without EJB

Transactions & DAOs (3)Transactions & DAOs (3)

Example for a JDBC-based DAO

public class ExampleJdbcDao extends JdbcDaoSupport {

public void clearDatabase() throws DataAccessException {    getJdbcTemplate().update("DELETE FROM imagedb");  }

  public void deleteImage(int imageId) throws DataAccessException {    getJdbcTemplate().update("DELETE FROM imagedb WHERE id=?", new Object[] {new Integer(imageId)});  }

  public int getNrOfImages() throws DataAccessException {    return getJdbcTemplate().queryForInt( "SELECT COUNT(*) FROM imagedb");  }}

Page 20: The Spring Framework J2EE without EJB

RemotingRemoting

Export POJOs as remote services▫ in server-side Spring applications▫ through Spring remote service exporter

Make remote services accessible▫ in client-side Spring applications▫ through Spring remote proxy factory

Protocol choice is configuration matter▫ Hessian, Burlap, SOAP, RMI, HTTP invoker▫ protocol to be chosen according to requirements

Support for integration of EJBs▫ through Spring EJB proxy factory▫ declarative proxies for Stateless Session Beans

Page 21: The Spring Framework J2EE without EJB

Further ServicesFurther Services

JMS Support▫ lightweight messaging

JCA Support▫ access to J2EE Connectors

Mail Support▫ JavaMailSender

Scheduling Support▫ Quartz, Timer

Web Application Support▫ Struts, JSF, WebWork, Tapestry▫ Spring Web MVC, Spring Web Flow

Page 22: The Spring Framework J2EE without EJB

Summary (1)Summary (1)

Spring is a popular Java application framework▫ core container, AOP framework▫ transactions, data access, remoting▫ dedicated support for J2EE environments▫ integrating with many existing solutions

Solves ubiquitous architectural issues▫ wiring and configuration of components▫ flexible configuration of interceptors▫ declarative transaction demarcation▫ implicit management of resources

Page 23: The Spring Framework J2EE without EJB

Summary (2)Summary (2)

Works in any environment▫ no special compilation or deployment steps▫ no special class loader▫ can run on J2EE, but not tied to J2EE▫ seamless switching between deployment scenarios

For any kind of application▫ J2EE web applications running on e.g. Tomcat▫ full J2EE applications running on e.g. WebLogic▫ rich clients (usually with J2EE server as backend)▫ standalone applications (with GUI or headless)

Page 24: The Spring Framework J2EE without EJB

http://www.springframework.orghttp://www.springframework.org

http://www.springframework.comhttp://www.springframework.com


Recommended