Академический Документы
Профессиональный Документы
Культура Документы
Who am I?
> Author of Seam in Act ion > Published art icles: Seamless JSF (developerWorks) Spring int o Seam (JavaWorld) > Commit ter on the JBoss Seam Project > Software consultant > Linux and open source advocat e > htt p:/ / www.mojavelinux .com
AGENDA
> > > > > > Why int egrat e? POJO int egrat ion EL integration ("Poor man's integration") Spring- Seam hybrid component s Inject ing Seam components int o Spring beans Persist ence contex t propagat ion and unified transact ions
AGENDA
> > > > > > Why integrate? POJO int egrat ion EL integration ("Poor man's integration") Spring- Seam hybrid component s Inject ing Seam components int o Spring beans Persist ence contex t propagat ion and unified transact ions
Why integrate?
> Applications are typically heterogeneous Shaped by their history; reflect ex pertise of developers > Ex tended inventory of unique functionality Seam
Perfect compliment to JSF, making it a compelling web framework choice Makes EL ubiquitous; stretches across entire stack Introduces real- world variable scopes (conversation, business process) Scopes the persistence context properly and manages global transactions Advanced AOP (AspectJ, Spring AOP) Lightweight and Java EE remoting (provides both client and endpoint) Prox y factory beans (e.g. JAX- RPC, JAX- WS, JMS, MBean) Template classes (e.g. JdbcTemplate, HibernateTemplate, JmsTemplate)
Spring
> Staged migration > Different philosophies: stateful vs stateless; annotations vs XML
AGENDA
> > > > > > Why int egrat e? POJO integration EL integration (aka "Poor man's integration") Spring- Seam hybrid component s Inject ing Seam components int o Spring beans Persist ence contex t propagat ion and unified transact ions
POJO integration
> Register POJO as Seam component Declare in Seam component descriptor (e.g. components.xml) Assign dependencies using component configuration < component name= "tournamentManager" scope= "APPLICATION" class= "...business.impl.TournamentManagerImpl" startup= "true"> < property name= "tournamentDao"> #{tournamentDao}< / property> < / component> References a Seam component > Just like a Spring bean definition, but Seam manages component > Useful for using classes from a third- party POJO library > Does not benefit from Spring services > May even have to emulate some Spring behavior (e.g. InitializingBean)
AGENDA
> > > > > > Why int egrat ion? POJO int egrat ion EL integration ("Poor man's integration") Spring- Seam hybrid component s Inject ing Seam components int o Spring beans Persist ence contex t propagat ion and unified transact ions
10
11
EL resolvers
> By default, EL looks for a JSF managed bean > Seam extends EL to look for a Seam component > Spring can also ex tend EL to look for a Spring bean Standard approach for integrating JSF with Spring > Primarily used to resolve ex pression root, but Seam takes EL further
#{beanName .propertyName}
JSF container
Seam container
Spring container
12
13
14
15
The verdict: EL
16
@Factory(value = "upcomingTournaments", scope = PAGE public List< Tournament> loadUpcomingTournaments() { return tournamentMgr.getUpcomingTournaments(); } }
17
18
19
20
> Allow Spring beans to consume (stateful) Seam components > Let Seam manage the persistence contex t for Spring Overall goal: Make integration more transparent and effective
21
AGENDA
> > > > > > Why int egrat e? POJO int egrat ion EL integration (aka "Poor man's integration") Spring- Seam hybrid components Inject ing Seam components int o Spring beans Persist ence contex t propagat ion and unified transact ions
22
23
< spring:contex t- loader config- locations= "/ WEB- INF/ spring- beans.x ml,classpath:spring- beansdao.xml"/ >
24
Seam
Spring
25
26
27
28
29
TournamentManagerCglibProxy
30
31
32
33
AGENDA
> > > > > > Why int egrat e? POJO int egrat ion EL integration ("Poor man's integration") Spring- Seam hybrid component s Injecting Seam components into Spring beans Persist ence contex t propagat ion and unified transact ions
34
35
Act: Singleton puts reference to a thread- bound object in a shared location (field on class) Consequence: Reference is exposed to concurrent threads Act: Object in longer- term scope holds reference to bean in shorter- term scope Consequence: Object in shorter- term scope outlives expected lifetime
Scope impedance
> Caused by: Inappropriate use of singletons Static injection Hard references
36
Can detect deadlock and timeout the call (throws exception) Timeout is configurable
> Spring and Seam both offer scoped prox ies to eliminate shared references
37
38
39
40
41
AGENDA
> > > > > > Why int egrat e? POJO int egrat ion EL integration ("Poor man's integration") Spring- Seam hybrid component s Inject ing Seam components int o Spring beans Persistence context propagation and unified transactions
42
43
44
45
class= "org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBea n"> < property name= "persistenceUnitName" value= "tournamentPU"/ > < property name= "dataSource" ref= "dataSource"/ > @In EntityManager entityManager < property name= "jpaDialect"> < bean class= "org.springframework.orm.jpa.vendor.HibernateJpaDialect"/ > < / property> < / bean>
components.xml
46
< bean id= "entityManagerFactorySpring " class= "org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBea n"> the one Spring will ... use < / bean> < bean id= "entityManagerFactory" class= "org.jboss.seam.ioc.spring.SeamManagedEntityManagerFactoryBean"> < property name= "persistenceContex tName" value= "entityManager"/ > < / bean>
components.xml
< persistence:managed- persistence- contex t name= "entityManager" entity- manager- factory= "#{entityManagerFactorySpring}" autocreate= "true"/ >
47
48
49
< bean id= "txManager " class= "org.springframework.orm.jpa.JpaTransactionManager"> < property name= "entityManagerFactory" ref= "entityManagerFactory"/ > < / bean> must be Seam's version
components.xml
50
51
Wrap up
> > > > Spring and Seam are not mutually ex clusive POJO- based development enables sharing Can start small with "Poor man's integration" (EL) In full stride, you are using both containers for their strengths Bring advanced AOP to Seam Leverage Spring's template classes, prox y factories, and exporters Seam can handle conversational state Seam can manage the persistence contex t correctly