The Spring Framework J2EE without EJB Jürgen Höller http://www.springframework.com [email_address]
Agenda <ul><li>J2EE Reviewed </li></ul><ul><li>Introducing the Spring Framework </li></ul><ul><li>Spring and J2EE </li></u...
J2EE Reviewed (1) <ul><li>Challenges of modern server-side software development </li></ul><ul><ul><li>multi-threaded execu...
J2EE Reviewed (2) <ul><li>J2EE specifies system services </li></ul><ul><ul><li>Servlets, JSP, JTA, JDBC, JMS, JavaMail </l...
J2EE Reviewed (3) <ul><li>Scope of J2EE is limited </li></ul><ul><ul><li>EJBs are coarse-grained components </li></ul></ul...
Spring Framework (1) <ul><li>Java / J2EE Application Framework </li></ul><ul><ul><li>based on Rod Johnson’s book “J2EE Des...
Spring Framework (2) <ul><li>Business objects as decoupled POJOs </li></ul><ul><ul><li>configuration and wiring through fr...
Spring Framework (3) <ul><li>Integration with existing solutions </li></ul><ul><ul><li>Object/Relational Mapping tools </l...
Spring and J2EE (1) <ul><li>J2EE provides standard system services </li></ul><ul><ul><li>to be leveraged by higher-level c...
Spring and J2EE (2) <ul><li>Spring is a de-facto standard Java / J2EE application framework </li></ul><ul><ul><li>typicall...
Spring and J2EE (3) <ul><li>Constantly increasing download numbers </li></ul><ul><ul><li>~30.000 downloads of every point ...
Core Container (1) <ul><li>&quot;Inversion of Control&quot; </li></ul><ul><ul><li>configuration and lifecycle of applicati...
Core Container (2) <ul><li>Fine-grained externalized configuration </li></ul><ul><ul><li>representing the internal structu...
Core Container (3) <bean id=&quot; dataSource &quot; class=&quot;org.apache.commons.dbcp.BasicDataSource&quot;> <property ...
AOP Framework (1) <ul><li>&quot;Aspect-Oriented Programming&quot; </li></ul><ul><ul><li>proxies for arbitrary POJOs </li><...
AOP Framework (2) <ul><li>Do not repeat code: factor out interceptor </li></ul><ul><ul><li>e.g. logging: configurable trac...
Transactions & DAOs (1) <ul><li>Transaction Strategy Abstraction </li></ul><ul><ul><li>PlatformTransactionManager SPI </li...
Transactions & DAOs (2) <ul><li>DataAccessException hierarchy </li></ul><ul><ul><li>independent of JDBC, Hibernate, JDO, e...
Transactions & DAOs (3) <ul><li>Example for a JDBC-based DAO </li></ul><ul><li>public class ExampleJdbcDao extends  JdbcDa...
Remoting <ul><li>Export POJOs as remote services </li></ul><ul><ul><li>in server-side Spring applications </li></ul></ul><...
Further Services <ul><li>JMS Support </li></ul><ul><ul><li>lightweight messaging </li></ul></ul><ul><li>JCA Support </li><...
Summary (1) <ul><li>Spring is a popular Java application framework </li></ul><ul><ul><li>core container, AOP framework </l...
Summary (2) <ul><li>Works in any environment </li></ul><ul><ul><li>no special compilation or deployment steps </li></ul></...
http://www.springframework.org   http://www.springframework.com
Upcoming SlideShare
Loading in …5
×

Tu1 1 5l

889 views

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
889
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Tu1 1 5l

  1. 1. The Spring Framework J2EE without EJB Jürgen Höller http://www.springframework.com [email_address]
  2. 2. Agenda <ul><li>J2EE Reviewed </li></ul><ul><li>Introducing the Spring Framework </li></ul><ul><li>Spring and J2EE </li></ul><ul><li>Core Container </li></ul><ul><li>AOP Framework </li></ul><ul><li>Transactions & Data Access </li></ul><ul><li>Remoting </li></ul><ul><li>Further Services </li></ul>
  3. 3. J2EE Reviewed (1) <ul><li>Challenges of modern server-side software development </li></ul><ul><ul><li>multi-threaded execution </li></ul></ul><ul><ul><li>resource and transaction management </li></ul></ul><ul><ul><li>remote service access </li></ul></ul><ul><ul><li>HTTP server integration </li></ul></ul><ul><li>Java 2 Enterprise Edition (J2EE tm ) </li></ul><ul><ul><li>set of specifications for standard application server infrastructure </li></ul></ul><ul><ul><li>industry standard: backed by Sun, IBM, Oracle </li></ul></ul><ul><ul><li>application server implements standard APIs </li></ul></ul><ul><ul><li>application uses standard APIs </li></ul></ul>
  4. 4. J2EE Reviewed (2) <ul><li>J2EE specifies system services </li></ul><ul><ul><li>Servlets, JSP, JTA, JDBC, JMS, JavaMail </li></ul></ul><ul><ul><li>builds on underlying standard Java runtime </li></ul></ul><ul><li>J2EE also specifies component models </li></ul><ul><ul><li>Servlets for HTTP endpoints </li></ul></ul><ul><ul><li>EJBs for middle tier components </li></ul></ul><ul><li>Focus on traditional 3-tier server layout </li></ul><ul><ul><li>focus on physical separation between tiers </li></ul></ul><ul><ul><li>middle tier always requires application server </li></ul></ul><ul><li>Low-level APIs </li></ul><ul><ul><li>direct usage in applications often cumbersome </li></ul></ul><ul><ul><li>comfortable high-level APIs? </li></ul></ul>
  5. 5. J2EE Reviewed (3) <ul><li>Scope of J2EE is limited </li></ul><ul><ul><li>EJBs are coarse-grained components </li></ul></ul><ul><ul><ul><li>mainly for (remote) service façades </li></ul></ul></ul><ul><ul><ul><li>special deployment effort for every component </li></ul></ul></ul><ul><ul><li>How to deal with fine-grained, co-located application objects? </li></ul></ul><ul><ul><ul><li>forced to use custom solutions </li></ul></ul></ul><ul><ul><ul><li>common: open source libraries / frameworks </li></ul></ul></ul><ul><li>How to run outside of an application server? </li></ul><ul><ul><li>not covered by traditional J2EE </li></ul></ul><ul><ul><li>important for unit tests and integration tests </li></ul></ul><ul><ul><li>also important for productive development </li></ul></ul>
  6. 6. Spring Framework (1) <ul><li>Java / J2EE Application Framework </li></ul><ul><ul><li>based on Rod Johnson’s book “J2EE Design & Development” (Wiley, 2002) </li></ul></ul><ul><ul><li>current book: &quot;J2EE Development without EJB&quot; (Rod Johnson, Jürgen Höller; Wiley, 2004) </li></ul></ul><ul><li>Focus on &quot;Plain Old Java Objects&quot; (POJOs) </li></ul><ul><ul><li>natural, generic component model for applications </li></ul></ul><ul><ul><li>flexible alternative to EJB, not tied to J2EE </li></ul></ul><ul><li>Open Source Project on SourceForge </li></ul><ul><ul><li>Apache license </li></ul></ul><ul><ul><li>since February 2003 </li></ul></ul><ul><ul><li>25 developers </li></ul></ul>
  7. 7. Spring Framework (2) <ul><li>Business objects as decoupled POJOs </li></ul><ul><ul><li>configuration and wiring through framework </li></ul></ul><ul><ul><ul><li>or usage as normal Java objects </li></ul></ul></ul><ul><ul><li>independent from the actual environment </li></ul></ul><ul><ul><ul><li>no unnecessary ties to a framework </li></ul></ul></ul><ul><ul><li>reusable in any kind of environment </li></ul></ul><ul><ul><ul><li>in particular: testability in unit / integration tests </li></ul></ul></ul><ul><li>Generic middleware services </li></ul><ul><ul><li>e.g. declarative transactions for POJOs </li></ul></ul><ul><ul><ul><li>flexible alternative to EJB CMT </li></ul></ul></ul><ul><ul><li>for all applications, including standalone </li></ul></ul><ul><ul><ul><li>leverage J2EE container services when available </li></ul></ul></ul>
  8. 8. Spring Framework (3) <ul><li>Integration with existing solutions </li></ul><ul><ul><li>Object/Relational Mapping tools </li></ul></ul><ul><ul><li>web frameworks </li></ul></ul><ul><ul><li>remoting protocols </li></ul></ul><ul><li>&quot;It‘s all about choice&quot; </li></ul><ul><ul><li>JDBC, Hibernate, JDO, Oracle TopLink, Apache OJB, iBATIS SQL Maps </li></ul></ul><ul><ul><li>Spring Web MVC, Spring Web Flow, Struts, WebWork, Tapestry, JSF </li></ul></ul><ul><ul><li>HTTP invoker, RMI invoker, conventional RMI, JAX-RPC (WSDL/SOAP), Hessian, Burlap </li></ul></ul>
  9. 9. Spring and J2EE (1) <ul><li>J2EE provides standard system services </li></ul><ul><ul><li>to be leveraged by higher-level components </li></ul></ul><ul><ul><li>Spring abstractions can run on top of J2EE </li></ul></ul>J2EE system services J2EE deployment and management Spring application container Spring service abstractions Application components
  10. 10. Spring and J2EE (2) <ul><li>Spring is a de-facto standard Java / J2EE application framework </li></ul><ul><ul><li>typically running on top of J2EE server </li></ul></ul><ul><ul><li>but: application components are not tied to J2EE </li></ul></ul><ul><li>Most popular &quot;lightweight container&quot; </li></ul><ul><ul><li>widespread adoption over the past 2.5 years </li></ul></ul><ul><ul><li>endorsed / supported by BEA, IBM, Oracle </li></ul></ul><ul><ul><ul><li>e.g.: support partnership for Spring on WebLogic </li></ul></ul></ul><ul><li>EJB3 specification will follow Spring model </li></ul><ul><ul><li>adopts some important ideas from Spring </li></ul></ul>
  11. 11. Spring and J2EE (3) <ul><li>Constantly increasing download numbers </li></ul><ul><ul><li>~30.000 downloads of every point release </li></ul></ul><ul><ul><li>>400.000 downloads overall </li></ul></ul><ul><li>Growing Spring ecosystem </li></ul><ul><ul><li>Spring sister projects </li></ul></ul><ul><ul><ul><li>Acegi Security, Spring Web Flow </li></ul></ul></ul><ul><ul><li>used or supported by many other products </li></ul></ul><ul><ul><ul><li>open source and commercial </li></ul></ul></ul><ul><ul><ul><li>e.g. Atlassian Confluence, Liferay Portal </li></ul></ul></ul><ul><ul><li>5 dedicated books on Spring already available </li></ul></ul><ul><ul><ul><li>by various authors </li></ul></ul></ul><ul><ul><ul><li>more books in the works </li></ul></ul></ul>
  12. 12. Core Container (1) <ul><li>&quot;Inversion of Control&quot; </li></ul><ul><ul><li>configuration and lifecycle of application objects </li></ul></ul><ul><ul><li>objects do not configure themselves, but get configured from the outside </li></ul></ul><ul><ul><li>objects don't know the origin of their configuration </li></ul></ul><ul><li>&quot;Dependency Injection&quot; </li></ul><ul><ul><li>&quot;setter-based&quot; (JavaBean properties) </li></ul></ul><ul><ul><li>&quot;constructor-based&quot; (constructor arguments) </li></ul></ul><ul><ul><li>alternative: &quot;Service Lookup&quot; </li></ul></ul><ul><ul><ul><li>for example: JNDI </li></ul></ul></ul>
  13. 13. Core Container (2) <ul><li>Fine-grained externalized configuration </li></ul><ul><ul><li>representing the internal structure of the application </li></ul></ul><ul><ul><ul><li>references to other components </li></ul></ul></ul><ul><ul><ul><li>configuration parameters </li></ul></ul></ul><ul><ul><li>enables flexible configuration management </li></ul></ul><ul><ul><ul><li>at fine-grained component level </li></ul></ul></ul><ul><ul><ul><li>switching between different deployment scenarios </li></ul></ul></ul><ul><li>XML bean definitions </li></ul><ul><ul><li>most common configuration format </li></ul></ul><ul><ul><li>often: separate admin properties file </li></ul></ul><ul><ul><ul><li>linked into XML bean definitions through placeholders </li></ul></ul></ul>
  14. 14. Core Container (3) <bean id=&quot; dataSource &quot; class=&quot;org.apache.commons.dbcp.BasicDataSource&quot;> <property name=&quot;driverClassName&quot; value=&quot;${jdbc.driver}&quot;/> <property name=&quot;url&quot; value=&quot;${jdbc.url}&quot;/> <property name=&quot;username&quot; value=&quot;${jdbc.username}&quot;/> <property name=&quot;password&quot; value=&quot;${jdbc.password}&quot;/> </bean> <bean id=&quot; itemDao &quot; class=&quot;org.springframework.samples.jpetstore.dao.ibatis.SqlMapItemDao&quot;> <property name=&quot;dataSource&quot; ref=&quot; dataSource &quot;/> <property name=&quot;sqlMap&quot; ref=&quot; sqlMap &quot;/> </bean> <bean id=&quot; petStore &quot; class=&quot;org.springframework.samples.jpetstore.domain.logic.PetStoreImpl&quot;> <property name=&quot;orderDao&quot; ref=&quot; orderDao &quot;/> <property name=&quot;itemDao&quot; ref=&quot; itemDao &quot;/> </bean>
  15. 15. AOP Framework (1) <ul><li>&quot;Aspect-Oriented Programming&quot; </li></ul><ul><ul><li>proxies for arbitrary POJOs </li></ul></ul><ul><ul><li>flexible combination of interceptors </li></ul></ul><ul><ul><li>no fixed component model (&quot;EJB a la carte&quot;) </li></ul></ul><ul><li>&quot;Cross-Cutting Concerns&quot; </li></ul><ul><ul><li>actions at the beginning/end of a method call </li></ul></ul>Target method Caller intercept
  16. 16. AOP Framework (2) <ul><li>Do not repeat code: factor out interceptor </li></ul><ul><ul><li>e.g. logging: configurable trace log </li></ul></ul><ul><ul><li>e.g. security: authorization checks </li></ul></ul><ul><ul><li>e.g. common exception handling </li></ul></ul><ul><ul><li>e.g. transaction demarcation </li></ul></ul><ul><li>Method interceptor </li></ul><ul><ul><li>interceptor can be applied to any methods </li></ul></ul><ul><ul><li>interceptor can be enabled/disabled </li></ul></ul><ul><ul><li>AOP Alliance: MethodInterceptor interface </li></ul></ul><ul><ul><li>reuse of pre-built interceptors </li></ul></ul>
  17. 17. Transactions & DAOs (1) <ul><li>Transaction Strategy Abstraction </li></ul><ul><ul><li>PlatformTransactionManager SPI </li></ul></ul><ul><ul><li>switching between JTA and native transactions </li></ul></ul><ul><li>Transaction Demarcation Options </li></ul><ul><ul><li>programmatic demarcation a la JTA </li></ul></ul><ul><ul><li>declarative demarcation for arbitrary POJOs </li></ul></ul><ul><li>Transaction Definitions </li></ul><ul><ul><li>all EJB CMT propagation codes supported </li></ul></ul><ul><ul><ul><li>REQUIRED, REQUIRES_NEW, etc </li></ul></ul></ul><ul><ul><li>optional transaction semantics beyond EJB </li></ul></ul><ul><ul><ul><li>nested, isolation level, timeout, read-only flag </li></ul></ul></ul>
  18. 18. Transactions & DAOs (2) <ul><li>DataAccessException hierarchy </li></ul><ul><ul><li>independent of JDBC, Hibernate, JDO, etc </li></ul></ul><ul><ul><li>unchecked, as most failures are not recoverable </li></ul></ul><ul><ul><li>subclasses like OptimisticLockingFailureException </li></ul></ul><ul><li>Support for DAO implementations </li></ul><ul><ul><li>implicit access to resources </li></ul></ul><ul><ul><li>many operations become one-liners </li></ul></ul><ul><ul><li>no try/catch blocks anymore </li></ul></ul><ul><li>Pre-built integration classes for many solutions </li></ul><ul><ul><li>JDBC: JdbcTemplate </li></ul></ul><ul><ul><li>Hibernate: HibernateTemplate </li></ul></ul>
  19. 19. Transactions & DAOs (3) <ul><li>Example for a JDBC-based DAO </li></ul><ul><li>public class ExampleJdbcDao extends JdbcDaoSupport { public void clearDatabase() throws DataAccessException {      getJdbcTemplate() .update(&quot;DELETE FROM imagedb&quot;);   }   public void deleteImage(int imageId) throws DataAccessException {      getJdbcTemplate() .update(&quot;DELETE FROM imagedb WHERE id=?&quot;, new Object[] {new Integer(imageId)});   }   public int getNrOfImages() throws DataAccessException {     return  getJdbcTemplate() .queryForInt( &quot;SELECT COUNT(*) FROM imagedb&quot;);   } } </li></ul>
  20. 20. Remoting <ul><li>Export POJOs as remote services </li></ul><ul><ul><li>in server-side Spring applications </li></ul></ul><ul><ul><li>through Spring remote service exporter </li></ul></ul><ul><li>Make remote services accessible </li></ul><ul><ul><li>in client-side Spring applications </li></ul></ul><ul><ul><li>through Spring remote proxy factory </li></ul></ul><ul><li>Protocol choice is configuration matter </li></ul><ul><ul><li>Hessian, Burlap, SOAP, RMI, HTTP invoker </li></ul></ul><ul><ul><li>protocol to be chosen according to requirements </li></ul></ul><ul><li>Support for integration of EJBs </li></ul><ul><ul><li>through Spring EJB proxy factory </li></ul></ul><ul><ul><li>declarative proxies for Stateless Session Beans </li></ul></ul>
  21. 21. Further Services <ul><li>JMS Support </li></ul><ul><ul><li>lightweight messaging </li></ul></ul><ul><li>JCA Support </li></ul><ul><ul><li>access to J2EE Connectors </li></ul></ul><ul><li>Mail Support </li></ul><ul><ul><li>JavaMailSender </li></ul></ul><ul><li>Scheduling Support </li></ul><ul><ul><li>Quartz, Timer </li></ul></ul><ul><li>Web Application Support </li></ul><ul><ul><li>Struts, JSF, WebWork, Tapestry </li></ul></ul><ul><ul><li>Spring Web MVC, Spring Web Flow </li></ul></ul>
  22. 22. Summary (1) <ul><li>Spring is a popular Java application framework </li></ul><ul><ul><li>core container, AOP framework </li></ul></ul><ul><ul><li>transactions, data access, remoting </li></ul></ul><ul><ul><li>dedicated support for J2EE environments </li></ul></ul><ul><ul><li>integrating with many existing solutions </li></ul></ul><ul><li>Solves ubiquitous architectural issues </li></ul><ul><ul><li>wiring and configuration of components </li></ul></ul><ul><ul><li>flexible configuration of interceptors </li></ul></ul><ul><ul><li>declarative transaction demarcation </li></ul></ul><ul><ul><li>implicit management of resources </li></ul></ul>
  23. 23. Summary (2) <ul><li>Works in any environment </li></ul><ul><ul><li>no special compilation or deployment steps </li></ul></ul><ul><ul><li>no special class loader </li></ul></ul><ul><ul><li>can run on J2EE, but not tied to J2EE </li></ul></ul><ul><ul><li>seamless switching between deployment scenarios </li></ul></ul><ul><li>For any kind of application </li></ul><ul><ul><li>J2EE web applications running on e.g. Tomcat </li></ul></ul><ul><ul><li>full J2EE applications running on e.g. WebLogic </li></ul></ul><ul><ul><li>rich clients (usually with J2EE server as backend) </li></ul></ul><ul><ul><li>standalone applications (with GUI or headless) </li></ul></ul>
  24. 24. http://www.springframework.org http://www.springframework.com

×