我可以使用Spring EL从属性文件中提取超时值,并在处理Spring Transactions / AOP时将其转换为整数吗?
这是代码
<tx:advice id="GlobalDataTxAdvice" transaction-manager="GlobalDataTransactionManager">
<tx:attributes>
<tx:method name="get*" no-rollback-for="javax.persistence.NoResultException,javax.persistence.NonUniqueResultException,org.springframework.dao.EmptyResultDataAccessException"/>
<tx:method name="find*" no-rollback-for="javax.persistence.NoResultException,javax.persistence.NonUniqueResultException,org.springframework.dao.EmptyResultDataAccessException"/>
<tx:method name="search*" read-only="true" no-rollback-for="javax.persistence.NoResultException,javax.persistence.NonUniqueResultException,org.springframework.dao.EmptyResultDataAccessException"/>
<tx:method name="*" timeout="${service.jta.timeout:60}"/>
</tx:attributes>
</tx:advice>
所以我希望默认事务超时为60秒,或者允许从属性占位符文件中提取超时(int值)。
但是当我部署它时,我得到:
weblogic.application.ModuleException :: org.xml.sax.SAXParseException:cvc-datatype-valid.1.2.1:'$ {service.jta.timeout:60}'不是'integer'的有效值。
答案 0 :(得分:0)
试试这个
<util:properties id="contextProperties" location="classpath:context.properties"/>
<tx:advice id="GlobalDataTxAdvice" transaction-manager="GlobalDataTransactionManager">
<tx:attributes>
<tx:method name="get*" no-rollback-for="javax.persistence.NoResultException,javax.persistence.NonUniqueResultException,org.springframework.dao.EmptyResultDataAccessException"/>
<tx:method name="find*" no-rollback-for="javax.persistence.NoResultException,javax.persistence.NonUniqueResultException,org.springframework.dao.EmptyResultDataAccessException"/>
<tx:method name="search*" read-only="true" no-rollback-for="javax.persistence.NoResultException,javax.persistence.NonUniqueResultException,org.springframework.dao.EmptyResultDataAccessException"/>
<tx:method name="*" timeout="#{ T(Integer).valueOf(contextProperties['timeout']?: 60)}"/>
</tx:attributes>
</tx:advice>