Search code examples
spring-transactionsspring-annotationsspring-el

can I inject @transactional properties into annotation?


I have services that are defined in a Spring context file and we are injecting the transactional properties using EL:

...
<bean id="basicStarTrans" class="java.lang.String">
   <constructor-arg value="PROPAGATION_SUPPORTS,readOnly" />
</bean>
...
<property name="transactionAttributes">
   <props>
      <prop key="save*">PROPAGATION_REQUIRED</prop>
      <prop key="delete*">PROPAGATION_REQUIRED</prop>
      <prop key="*"><b>#{basicStarTrans}</b></prop>
   </props>
</property>

I have a few services that are defined using the @Service annotation. Is it possible to inject a property similar to the way we do it in the xml file and what would the syntax be? i.e:

@Transactional("#{transactionalSettings}")

Solution

  • Have a deeper look at the <tx:> namespace. I think it'll have what you need:

    http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html