Announcement Announcement Module
Collapse
No announcement yet.
Context property default for field that is an integer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Context property default for field that is an integer

    In using Spring Transaction schema (with Spring 3.0.5), I want to be able to pull the timeout for a transaction from a property file. The problem is that the field in the transaction schema is defined as an integer and therefore an error is received that I cannot do the property substitution.

    Here is the code

    Code:
    <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>
    So I want the default transaction timeout to be 60 seconds, or allow the timeout (int value) to be pulled from a property placeholder file.

    But when I deploy this I get:

    weblogic.application.ModuleException: :org.xml.sax.SAXParseException:cvc-datatype-valid.1.2.1: '${service.jta.timeout:60}' is not a valid value for 'integer'.

    I had a suggestion to do the following, but it didn't work either:

    Code:
    <tx:method name="*" timeout="#{ T(Integer).valueOf(contextProperties['timeout']?: 60)}"/>

  • #2
    If you are using Maven, one practical solution is something like
    pom.xml
    Code:
    <resources>
          <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
              <include>**/*.xml</include>
            </includes>
          </resource>
     </resources>
    ...
    <properties>
      <service.jta.timeout>60</service.jta.timeout>
    </properties>
    and

    Code:
    <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}"/>
        </tx:attributes>
    </tx:advice>
    You can find more here http://maven.apache.org/plugins/mave...es/filter.html

    Comment


    • #3
      Thanks for the suggestion, I am aware of the filter capability in Maven and unfortunately that won't help me. I want the timeout value to use a property so that I can change it for multiple environments. My question still stands as to whether elements such as timeout can be property driven.

      Comment


      • #4
        Hi jaybytez,

        Maven manage well properties for multiple environments as it is designed for this kind of things.
        But if your requirement is really relied on .properties file, you can do something like:


        Code:
        <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}"/>    
        </tx:attributes></tx:advice>
        and

        Code:
        <context:property-placeholder location="jta.properties"/>
        Last edited by wang.yunbo; Jun 28th, 2012, 12:14 PM. Reason: Make it more clear

        Comment


        • #5
          Maven is not what I want to use. We don't create war files per environment, hence the need for Spring and the property placeholder. Otherwise Maven would have to be used to build an env specific war for each env...that is not what I want.

          Also, I appreciate your response but unless I am confused...you didn't read my post.

          I know how to use the property-placeholder, but you cannot utilize the property placeholder and put timeout="${service.timeout}" because Spring will fail with the validation error I posted above because the schema defines the timeout as an integer. What I want to know is if there is away around the validation error so that I can represent timeout (or schema attributes that are not Strings) as a property-placeholder (with a default value).

          Comment

          Working...
          X