可配置的交易超时:设置TX:建议/TX:属性/TX:Method/@timeout使用Spring EL
根据春季配置文件,我需要可配置的交易超时。因此,我想设置tx:建议/TX:属性/TX:Method/@timeout
使用Spring EL。当我为默认值(BEANS)名称空间中的标签的属性进行类似设置时,它可以正常工作,而在TX名称空间中不进行。
看来模式验证在属性替代之前运行,或者根本没有替换:
Line 21 in XML document from class path resource [spring-core-main.xml] is invalid;
nested exception is org.xml.sax.SAXParseException; lineNumber: 21; columnNumber: 148;
cvc-datatype-valid.1.2.1: '#{transactionTimeoutSeconds}' is not a valid value for 'integer'.
我的配置看起来像:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<bean id="transactionTimeoutSeconds" class="java.lang.Integer">
<constructor-arg value="30" />
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" timeout="#{transactionTimeoutSeconds}" />
</tx:attributes>
</tx:advice>
有可能实现我想要使用XML配置的目标吗?
I need a configurable transaction timeout according to Spring profiles. So I would like to set tx:advice/tx:attributes/tx:method/@timeout
using Spring EL. It works fine when I do a similar setup for an attribute of a tag in the default (beans) namespace, but not in the tx namespace.
It looks like that a schema validation runs before property substitution, or there is no substitution at this place at all:
Line 21 in XML document from class path resource [spring-core-main.xml] is invalid;
nested exception is org.xml.sax.SAXParseException; lineNumber: 21; columnNumber: 148;
cvc-datatype-valid.1.2.1: '#{transactionTimeoutSeconds}' is not a valid value for 'integer'.
My configuration looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<bean id="transactionTimeoutSeconds" class="java.lang.Integer">
<constructor-arg value="30" />
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" timeout="#{transactionTimeoutSeconds}" />
</tx:attributes>
</tx:advice>
Is it possible to achieve what I want using XML configuration?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来属性替代在此属性中不起作用。最终,我通过将整个TX内容放入个人资料来解决了问题:
It looks like property substitution does not work in this attribute. Finally I solved the problem by putting the whole tx stuff into profiles: