PDA

View Full Version : Example Spring


gamblingman
Oct 27th, 2004, 12:46 AM
Hi,
I have to write example EJB use Spring + Hibernate that can run on Application server as: Orion, WebSphere... and can run servlet container such as Tomcat. It's mean that example can run EJB or non EJB.
Has anyone have example like that. Can you post it here.
Thank for reading!

gamblingman
Oct 27th, 2004, 06:36 AM
Has anyone have that example.
Please help me soon!
Thank for reading!

agile_boy
Dec 10th, 2004, 04:54 AM
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>EmsDataSource</value>
</property>
</bean>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFact oryBean">
<property name="dataSource"><ref bean="dataSource"/></property>
<property name="mappingResources">
<list>
<value>com/xxx/*.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.InformixDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
<prop key="hibernate.cache.provider_class">net.sf.hibernate.cache.HashtableCacheProvider</prop>
<!--prop key="hibernate.hbm2ddl.auto">update</prop-->
</props>
</property>
</bean>
<!-- Spring Data Access Exception Translator Defintion -->
<bean id="jdbcExceptionTranslator" class="org.springframework.jdbc.support.SQLErrorCodeSQLEx ceptionTranslator">
<property name="dataSource"><ref bean="dataSource"/></property>
</bean>

<!-- Hibernate Template Defintion -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate.HibernateTemplat e">
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
<property name="jdbcExceptionTranslator"><ref bean="jdbcExceptionTranslator"/></property>
</bean>

<!-- Hibernate Transaction Manager Definition -->
<bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransac tionManager">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
<bean id="txProxyTemplate" abstract="true"
class="org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean">
<property name="transactionManager">
<ref local="transactionManager"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="create*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>

<bean id="emsResourceService" parent="txProxyTemplate">
<property name="target">
<ref local="emsResourceServiceTarget"/>
</property>
</bean>
<bean
id="emsResourceServiceTarget"
class="com.xxx.service.impl.EmsEquipmentServiceImpl">

<property name="equipmentDao">
<ref bean="equipmentDao"/>
</property>
</bean>

<bean
id="equipmentDao"
class="com.xxx.dao.spring.hibernate.EquipmentDaoHibernate Impl">
<property name="hibernateTemplate">
<ref bean="hibernateTemplate"/>
</property>
</bean>

that configuration file is tested in Weblogic8.1

realdahan
Jan 15th, 2005, 08:59 AM
I'm still puzzled by Spring configuration for a ear file. Do I need an applicationContext.xml file? Seems like the only xml file I need is beanRefContext.xml. Correct. By the way, where do I put the xml files in the ear file? under APP-INF/class? or META-INF/? If I need to set up logging inside the ear file, where do I put the log4j.properties or log4j.xml and can spring pick it up automatically?

Thanks.