Spring @Transactional value param with SpEL(Spring 表达式语言) [英] Spring @Transactional value param with SpEL (Spring expression language)
问题描述
在我的一个服务类中,我注释了一些方法:
In one of my service classes I have some methods annotated as such :
@Transactional(value="foodb")
public Bar getMeSomething(){
}
我最近通过 Spring EL 的强大功能了解了 @Value 来获取存储在属性文件中的一些值.比如
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}")
这就像一个魅力.
现在我正在尝试做同样的事情
Now I'm trying to do the same with
@Transactional(value="${my.db.name}")
没有成功......
我收到以下异常:
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!
我正在尝试做的事情甚至得到 Spring 的支持吗?
Is what I am trying to do even supported by Spring ?
我该怎么做才能在@Transactional 注释中获取 my.db.name 值
What can I do to get the my.db.name value inside that @Transactional annotation
谢谢
推荐答案
不,不支持.
这是 org.springframework.transaction.annotation.SpringTransactionAnnotationParser 的摘录
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
这篇关于Spring @Transactional value param with SpEL(Spring 表达式语言)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!