Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Practices
Better architecture by design
JAVAWUG BOF 27, Skills Matter, London
*PP* © 2007
Peter Pilgrim
Java EE Software Designer Architect
Independent Contractor
Financial Services
Java Champion
http://jroller.com/page/peter_pilgrim
http://jroller.com/page/javawug
Talk Outline
2
What is Spring?
3
What is Spring Version 1?
Bean Factory
Container
MVC Remoting
Declarative
Mail Scheduling
TX
4
What is Spring Version 2?
Dynamic Java 5
AOP
Bean Factory
Container Remoting
Servlet MVC
Annotations (TX) Task
Portlet MVC Executor
XML Namespaces Scripting Languages
Tag Libs
Declarative
Scheduling
Mail TX
5
What is expected in Spring Version 2.1?
Declarative
Spring Security Mail TX Scheduling
6
Goals of Spring 2.0
Backwards compatible
Annotation Driven Transactions
Simplified Java 5 Support
XML Namespace extension for ease-of-configuration
Improved JMS Messaging, local and XA transactions
Task Executor
AspectJ library support
JPA Integration
Portlet MVC
7
Goals of Spring 2.1
8
Goals of Spring 2.1
9
Future of Spring Development Java EE JSR 316
10
Configuration of Transactions: Manager & Advice
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="...">
<bean id="txManager"
class="org.springframework.orm.hibernate3.
HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
11
Configuration of Transactions: Pointcuts
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="...">
<aop:config>
<aop:pointcut id="projectServiceOperation"
expression="execution(* websitetracker.service.*.*(..))" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="projectServiceOperation" />
</aop:config>
<aop:config>...</aop:config>
...
</beans>
12
Configuration: Hibernate Session Factory
<beans ...>
<bean id="sessionFactory" class="org.springframework.orm.
hibernate3.LocalSessionFactoryBean">
<property name="mappingResources">
<list>
<value>websitetracker/domain/IpAddressReverse.hbm.xml</value>
<value>websitetracker/domain/Website.hbm.xml</value>
</list></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">false</prop>
</props></property>
<property name="dataSource"><ref bean="dataSource"/></property>
<property name="eventListeners">
<map>
<entry key="merge">
<bean class="org.springframework.orm.hibernate3.support.
IdTransferringMergeEventListener" />
</entry></map></property>
</bean> ...
</beans>
13
Configuration: Hibernate DAO & Services
<beans ...>
<bean id="ipAddressReverseDao"
class="websitetracker.dao.IpAddressReverseDao" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="trackReportService"
class="websitetracker.engine.impl.TrackReportServiceImpl" >
<property name="hibernateTemplate"
ref="hibernateTemplate" />
</bean> ...
</beans>
14
Multiple Application Contexts
15
Define A Master Application Context
</list>
</constructor-arg>
<constructor-arg index="1"><value>true</value></constructor-arg>
</bean>
</beans>
16
Share Contexts Among Spring Managed EJBs
17
Spring Managed EJB Example
public TradeRouteProcessorRemoteEJB() {
super();
setBeanFactoryLocator(
ContextSingletonBeanFactoryLocator
.getInstance(“classpath:fitrader-context.xml”));
setBeanFactoryLocatorKey(“FI-TRADER”);
}
18
Test Driven Development
19
Easy Mock Advice
20
Maven 2.0 Spring Framework Java EE Setup
21
A Generic DAO
22
Generic DAO Interface
23
Abstract Persistence DAO
24
Concrete Generic DAO
public IpAddressReverseDao() {
super( IpAddressReverse.class );
}
@SuppressWarnings("unchecked")
public List<IpAddressReverse> getAll() {
return getHibernateTemplate().find(
"select i from IpAddressReverse as i");
}
...
}
25
Executive Summary
26
Time for Questions?
Q&A
27
Illustration
28