Spring J2EE Framework: Ram A. Rao May 15 05
Spring J2EE Framework: Ram A. Rao May 15 05
Ram A. Rao
May 15th ‘05
}catch(Exception e){
}
}
// Spring sets the value thru runtime injection!
private setOpportunityDAO(OpportunityDAO oppDao){
this.oppDAO = oppDao;
}
Business layer
Integrates with EJBs
Provides integration with components using IoC.
Transaction (declarative and programmatic)
Persistence layer
DAO pattern implementation
Template support for Hibernate, iBatis DataMapper and JDBC
Transaction management, Exception translation, connection
management.
General
Email, JNDI, WebServices
<bean id=“CampaignServiceTarget"
class="com.corp.CampaignServiceImpl">
<property name=“promotionService">
<ref bean=“promotionService" />
</property>
<property name=“count">2</property>
</bean>
ContextLoaderPlugin
Loads a Spring application context for the Struts
ActionServlet.
Struts Actions are managed as Spring beans.
<plug-in
className="org.springframework.web.struts.Conte
xtLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml"/>
</plug-in>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<!-- listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener -->
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<bean id=“campaignService"
class=“com.corp.CampaignServiceImpl">
<session id=“CampaignService">
<ejb-name>CampaignService</ejb-name>
<local-home>com.corp.ejb.CampaignServiceLocalHome</local-home>
<local>com.corp.ejb.CampaignServiceLocal</local>
<ejb-class>com.corp.ejb.CampaignServiceBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
<env-entry>
<env-entry-name>ejb/BeanFactoryPath</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>ejbContext.xml</env-entry-value>
</env-entry>
<ejb-local-ref id="EJBLocalRef_1136316508000">
<ejb-ref-name>ejb/CampaignService</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>com.corp.ejb.services.CampaignServiceLocalHome</local-home>
<local>com.corp.ejb.services.CampaignServiceLocal</local>
<ejb-link>CampaignService</ejb-link>
</ejb-local-ref>
</session>
<bean id="accountService"
class=“LocalStatelessSessionProxyFactoryBean">
<property name="jndiName">
<value>ejb/CampaignServiceHome</value>
</property>
<property name="businessInterface">
<value>com.corp.services.CampaignService</value>
</property>
</bean>
EJB Local:
/**
* Local interface for Enterprise Bean: CampaignService.
*/
public interface CampaignServiceLocal extends
javax.ejb.EJBLocalObject, CampaignService {
}
/**
* Bean implementation class for Enterprise Bean:
CampaignService
*/
public class CampaignServiceBean extends
AbstractStatelessSessionBean
implements CampaignService {
“campaignService";
private Campaign service;
<bean id=“campaignServiceTarget"
class="com.corp.services.CampaignServiceImpl">
<property name=“promoDAO">
<ref bean=“promoDAO" />
</property>
</bean>
<bean id=“localTransactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactio
nManager">
<property name="dataSource">
<ref local="springContainerDataSource" />
</property>
</bean>
<bean id="wsJtaTm"
class="org.springframework.transaction.jta.WebSphereTransaction
ManagerFactoryBean"/>
<bean id=“distTransactionManager"
class="org.springframework.transaction.jta.JtaTransactionManage
r">
<property name="transactionManager" ref="wsJtaTm" />
<property name="userTransactionName"><null /></property>
</bean>
beanId:CampaignServiceTxn
-TransactionProxyFactoryBean
TransactionAttributes
beanId:CampaignServiceTarget beanId:TransactionManager
-CampaignServiceImpl - JTATransactionManager
beanId:promoDAO beanId:hibernateSessionFactory
- HibernatePromotionDAO MappingResources
- setHibernateSessionFactory() HibernateProperties
<bean id="springContainerDataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>jdbc/CustomerDB</value>
</property>
</bean>
<bean id=“promoDao"
class="com.corp.dao.HibernatePromotionDao">
<property name="sessionFactory">
<ref local="hibernateSessionFactory" />
</property>
</bean>
Support for
JdbcDaoSupport
Provides callback methods for row iteration
HibernateDaoSupport
Initializes Hibernate session factory
Provides templates to invoke Hibernate API or the
session
SqlMapDaoSupport
Provides template for iBatis SQLMaps
Support similar to Hibernate template
return promo;
}
public void setAppDataSource (DataSource ds) {
this.appDataSource = ds;
}
session.save(promo);
return promo;
}
});
}
...
}
beanId:methodAuthzAdvisor beanId:methodAuthzAdvice
- RegexpMethodPointcutAdvisor - AuthorizationAdvice
PointCut pattern(.*)
Before
CampaignServiceImpl
-createCampaign(String);
if (!isValidAccess) {
//Unauthorized user access, do not process any
further.
throw new Exception();
}
}
..
Last Update: 5/15/06 48
}
Spring Interceptor Injection
beanId:methodAuthzAdvisor
- RegexpMethodPointcutAdvisor
PointCut pattern(.*)
beanId:CampaignServiceTxn beanId:methodAuthzAdvice
-TransactionProxyFactoryBean - AuthorizationAdvice
TransactionAttributes
beanId:CampaignServiceTarget beanId:TransactionManager
-CampaignServiceImpl - JTATransactionManager
beanId:promoDAO beanId:hibernateSessionFactory
- HibernatePromotionDAO MappingResources
- setHibernateSessionFactory() HibernateProperties
<bean id=“promotionService"
class="org.springframework.aop.framework.ProxyFactor
yBean">
<property name="proxyInterfaces">
<value>com.corp.CampaignService</value>
</property>
<property name="target">
<ref local=“CampaignServiceTxn"/>
</property>
<property name="interceptorNames">
<list>
<value>methodAuthzAdvisor</value>
</list>
</property>
</bean>
JavaMail helpers
JMS implementation
JNDI lookup
Integration with iText for PDF generation
Helper classes for Http Invocation and WebServices
.. and a whole lot of other abstractions
Spring – www.springframework.org
Inversion of Control -
http://www.martinfowler.com/articles/injection.html
Java Development With Spring Framework –
Johnson, Hoeller et al.
Spring in Action – Walls, Breidenbach