• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring Transaction using AOP in EJB Project

 
gokul maha
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
gokul maha
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 85
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can try this, have a web.xml and define a servlet in it like:


then define a main class like:

 
gokul maha
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 85
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 85
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah it will...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic