aspose file tools*
The moose likes Spring and the fly likes Spring Transaction using AOP in EJB Project Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring Transaction using AOP in EJB Project" Watch "Spring Transaction using AOP in EJB Project" New topic
Author

Spring Transaction using AOP in EJB Project

gokul maha
Greenhorn

Joined: Jun 27, 2006
Posts: 25
Hi,

My application has only EJB project and no Web tier.
I want to implement spring declarative transaction management using AOP.
How to load the spring context xml?

Thanks in advance,
Gokul
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Unfortunately, the only solution with EJBs is to have your EJBs extend the Spring class that makes EJB Spring App Context aware.

Good Luck

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
gokul maha
Greenhorn

Joined: Jun 27, 2006
Posts: 25
I am NOT using EJBs (Session beans) for Transaction Management. I want to use Spring POJO Declarative Transaction Management using AOP. Only entry point to the application is MDB.
Since there is not web project, I am not sure how to load the application context xml where the transaction attributes are defined and let the container be aware of it.

<bean id="sampleManager" class="test.SampleManager">
<property name="dataAccessor" ref ="dataAccessor"/>
<property name="dataSource">
<ref local="dataSource"/>
</property>
</bean>

<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="*" propagation = "REQUIRED"/>
</tx:attributes>
</tx:advice>

<aop:config>
<aop:pointcut id="testOp" expression="execution(* test.SampleInterface.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="testOp"/>
</aop:config>

<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>

SampleManager implements SampleInterface.


Could you please help on this? Thanks.
Vivek K Singh
Ranch Hand

Joined: Dec 22, 2009
Posts: 85

you can try this, have a web.xml and define a servlet in it like:


then define a main class like:



SCJP 6
gokul maha
Greenhorn

Joined: Jun 27, 2006
Posts: 25
Thanks Vivek. But want to know, Can we use web.xml in EJB project?
How this web.xml will be triggered. I dont have any web module/project at all. My application is triggered using MDB.
Vivek K Singh
Ranch Hand

Joined: Dec 22, 2009
Posts: 85

yes you can do that: http://www.eclipse.org/webtools/community/tutorials/ejbtutorial/buildingejbs.html

Also, there are other ways to do this as well. You can have a main method to load the Spring beans. Where to trigger it from can be a bit tricky...
gokul maha
Greenhorn

Joined: Jun 27, 2006
Posts: 25
Thanks. I will try this option.
Once loaded using the above method, the container will take care of the transaction using the attributes in the context xml right ?
Vivek K Singh
Ranch Hand

Joined: Dec 22, 2009
Posts: 85

yeah it will...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring Transaction using AOP in EJB Project