SpringFramework.Java Developer Session

streakconvertingSoftware and s/w Development

Dec 13, 2013 (3 years and 8 months ago)

79 views

Copyright © 2005 Finetix LLC

All Rights Reserved



0

SpringFramework.Java Developer Session

Solomon Duskis

The Peer Frameworks Series
-

.Net and Java


Copyright © 2005 Finetix LLC

All Rights Reserved



1

SpringFramework Release


"Simple thing should be simple, and complex things should be
possible."
-

Alan Kay


"Unless simple things are simple, complex things are impossible."
-

Rod Johnson


Spring 0.9 announced at The Serverside Java Symposium 2002


Copyright © 2005 Finetix LLC

All Rights Reserved



2

J2EE Design and Development




Copyright © 2005 Finetix LLC

All Rights Reserved



3

Anti
-
EJB


Spring In Action (Craig Walls)


EJB is complex, not for just being
complex. It is complex because it attempts to provide solutions for
complex problems


The complex problems include distributed transactions across a
variety of system types, including Relational Databases, MoM and
Legacy Systems


2004

Copyright © 2005 Finetix LLC

All Rights Reserved



4

J2EE Development without EJB

Copyright © 2005 Finetix LLC

All Rights Reserved



5

Martin Fowloer on IoC Containers


Martin Fowler (IoC Containers and the DIP)



Inversion of control
is a common characteristic of frameworks, so saying that these
lightweight containers are special because they use inversion of
control is like saying my car is special because it has wheels… For
this new breed of containers the inversion is about how they lookup a
plugin implementation.

Copyright © 2005 Finetix LLC

All Rights Reserved



6

Today



Copyright © 2005 Finetix LLC

All Rights Reserved



7

People


Interface21





International consulting company run by Rod Johnson. The Interface21
consultants are the core Spring Framework Developers.



Matt Raible
: Creator of AppFuse


Strategic adoption in many enterprises moving away from traditional costly,
inefficient J2EE approaches


This new paradigm is realized through WebLogic Real Time (WLRT).



Extensive and growing usage across many industrites including: Retail and
Investment banks, Insurance companies (US and Europe) and even
Governments.


In Banking: 5 out of the world's 10 largest banks are Spring users and
Interface21 clients. That's pretty impressive IMO.


Spring 2.0: builds on the solid base, pursues vision of POJO
-
based
development and adds new capabilities and makes many tasks more
elegant. They're hoping to release 2.0 in May 2006.

Copyright © 2005 Finetix LLC

All Rights Reserved



8

Java Frameworks Galore



JNDI Abstraction
EJB Access (SLSB - local and Remote)
Spring JMS Pojos
JCA
Convenience EJB implementation classes
(SLSB, SFSB, MDB)
Spring Framework
Bean Management
UI
Spring MVC
Spring Portlets
Spring Webflow
Spring RCP
JSP
JSF
Tiles
(SiteMesh)
Velocity
FreeMarker
XSLT
PDF (iText)
Excel (POI)
JSTL
Spring MVC Tags
(1.0 & 2.0)
View Support
Frameworks
Struts
Tapestry
WebWork
Spring MVC
Spring Portlets
Spring Original
Middleware
Remoting
RMI
Hessian
Burlap
HTTP Invocation
JAX-RPC
XFire
J2EE
Spring Original
DAO Abstraction
Email Abstraction
Remoting Abstractions
Configuration
Spring 1.0 XML
Spring "Simplified" XML (2.0)
BeanFactory et al
PropertyEditors
Databinding
Validation
Spring AOP
AspectJ
AOP
Acegi - Security
Spring transaction
Managemnt
JMX
Value Add
Annotations
JDK 5.0 Annotations
AspectJ Annotation integration
JPA Annotations
Jakarta Common Attributes
Task Scheduling
OpenSymphony Quartz
JDK Timer
Spring TaskExecutor
(built on JDK 5.0 Executors)
JRuby
BeanShell
Groovy
Testing
JUnit
DBUnit
Grinder
Dynamic
Languages
Persistence
Spring JPA Annotation
Unified Exception Handling
Transaction Managemnt
Spring JDBC
Hibernate
IBatis
JDO
JPA
Spring Original
Persistence
Frameworks
TopLink
Apache OJB
Spring JDBC
Copyright © 2005 Finetix LLC

All Rights Reserved



9

Spring DataSource Configuration

<bean id="myDataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy
-
method="close">


<property name="driverClassName"
value="org.hsqldb.jdbcDriver"/>


<property name="url" value="jdbc:hsqldb:hsql://localhost:9001"/>


<property name="username" value="sa"/>


<property name="password" value=""/>

</bean>

<bean id="myDataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">


<property name="jndiName" value="java:comp/env/jdbc/myds"/>

</bean>

Copyright © 2005 Finetix LLC

All Rights Reserved



10

Spring Session Factory Configuration

<bean id="sessionFactory"
class="org.springframework.orm.hibernate.LocalSessionFactoryBean”
>


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


<property name="mappingResources">


<list>


<value>product.hbm.xml</value>


</list>


</property>


<property name="hibernateProperties">


<props>


<prop key="hibernate.dialect">${hibernate.dialect}</prop>


</props>


</property>

</bean>

Copyright © 2005 Finetix LLC

All Rights Reserved



11

Spring Dao Configuration

<bean id="myProductDao" class="product.ProductDaoImpl">


<property name="sessionFactory" ref="mySessionFactory"/>

</bean>

Copyright © 2005 Finetix LLC

All Rights Reserved



12

Java Hibernate Dao Code



public class ProductDaoImpl extends HibernateDaoSupport

implements ProductDao {


public Collection loadProductsByCategory(String category)


throws DataAccessException {


return getHibernateTemplate().find(


"from test.Product product where product.category=?", category);


}

}

Copyright © 2005 Finetix LLC

All Rights Reserved



13

Declarative Transaction Configuration

<bean id="myTxManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">


<property name="sessionFactory" ref="mySessionFactory"/>

</bean>

<bean id="myTxInterceptor"


class="org.springframework.transaction.interceptor.TransactionInterceptor">


<property name="transactionManager" ref="myTxManager"/>


<property name="transactionAttributeSource">


<value>


product.ProductService.increasePrice*=PROPAGATION_REQUIRED


product.ProductService.someOtherBusinessMethod=PROPAGATION_MANDATORY


</value>


</property>

</bean>

<bean id="myProductServiceTarget" class="product.ProductServiceImpl">


<property name="productDao" ref="myProductDao"/>

</bean>

<bean id="myProductService" class="org.springframework.aop.framework.ProxyFactoryBean">


<property name="proxyInterfaces">


<value>product.ProductService</value>


</property>


<property name="interceptorNames">


<list>


<value>myTxInterceptor</value>


<value>myProductServiceTarget</value>


</list>


</property>

</bean>

Copyright © 2005 Finetix LLC

All Rights Reserved



14

Service Code, Fully Transactional via IoC/AOP

public class ProductServiceImpl implements ProductService {


private ProductDao productDao;


public void setProductDao(ProductDao productDao) {


this.productDao = productDao;


}


public void increasePriceOfAllProductsInCategory(final String category)
{


List productsToChange =
this.productDAO.loadProductsByCategory(category);


...


}




...

}