Question

In one of my service classes I have some methods annotated as such :

@Transactional(value="foodb")
public Bar getMeSomething(){
}

I recently learned about @Value with the power of Spring EL to get some values stored in a properties file. such as

@Value("${my.db.name}")

which works like a charm.

Now I'm trying to do the same with

@Transactional(value="${my.db.name}") 

with no success ...

I get the following exception :

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named '${my.db.name}' is defined: No matching PlatformTransactionManager bean found for qualifier '${my.db.name}' - neither qualifier match nor bean name match!

Is what I am trying to do even supported by Spring ?

What can I do to get the my.db.name value inside that @Transactional annotation

Thanks

Was it helpful?

Solution

Nope, it's not supported.

Here's an excerpt from org.springframework.transaction.annotation.SpringTransactionAnnotationParser

public TransactionAttribute parseTransactionAnnotation(Transactional ann) {
    RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
    rbta.setPropagationBehavior(ann.propagation().value());
    rbta.setIsolationLevel(ann.isolation().value());
    rbta.setTimeout(ann.timeout());
    rbta.setReadOnly(ann.readOnly());
    rbta.setQualifier(ann.value()); // <<--- this is where the magic would be
    // if it was there, but it isn't
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top