Announcement Announcement Module
Collapse
No announcement yet.
is it possible to use constants names in spring context ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • is it possible to use constants names in spring context ?

    It seems not beeing possible to set a property value using a java constant. For example, to setup a PropertyPlaceholderConfigurer, whe need to set "systemPropertiesMode" to value "2". It would be so fine to set :
    Code:
    <property name="systemPropertiesMode" 
        value="PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
    Is there some plan to add such a functionnality to spring XML context ?

  • #2
    Example:

    Code:
    <bean id="java.util.concurrent.TimeUnit.MILLISECONDS"
    		class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean"/>
    MILLISECONDS is a static field.

    Comment


    • #3
      Thanks for info, I did never used this factoryBean.

      It can be usefull to avoid using constants values, but makes my spring context file huge !

      Comment


      • #4
        Originally posted by ndeloof
        Thanks for info, I did never used this factoryBean.

        It can be usefull to avoid using constants values, but makes my spring context file huge !
        Yes.. I hope in the near future it will be easier to access data from objects. Maybe with something like OGNL.

        Code:
        <bean id="foo" class="Foo">
             <constructor-arg index="0" value="ognl&#58;java.util.concurrent.TimeUnit.SECOND"/>
             <constructor-arg index="1" value="ognl&#58;60*60*numberOfHoursBean"/>
        </bean>
        It makes the bean container more powerfull and easier to use.

        [edit]
        http://opensource.atlassian.com/proj...rowse/SPR-1003

        It will be part of Spring 1.4... hmm.. long time to wait. And I don`t want to write extra beans.. I want to access java memory directly, else you will get to complex configuration files. Maybe introduce a ognlvalue in the xml.


        Code:
        <bean id="foo" class="Foo">
             <constructor-arg index="0" ognlvalue="java.util.concurrent.TimeUnit.SECOND"/>
             <constructor-arg index="1" ognlvalue="60*60*numberOfHoursBean"/>
        </bean>

        Comment


        • #5
          Originally posted by ndeloof
          ..., but makes my spring context file huge !
          Agreed.I have a context file that consists solely of these beans. While the OGNL enhancement would be great, the ability to handle enumerated/constant types through:
          Code:
          <property name="supportedType">
              <constant>a.b.c.Types.TYPE_A</constant>
          </property>
          Would go a long way.

          Comment


          • #6
            You can always commit code which will speed things up . Not to mention you'll get to implement your ideas first hand.

            Comment


            • #7
              Originally posted by costin
              You can always commit code which will speed things up .
              To introduce OGNL would require a change in the spring-xml so you don`t have to create OGNL factory beans (I don`t like factory beans for ognl because they will bloat your appcontext) and I think the appcontext is allready verbose at the moment.

              Not to mention you'll get to implement your ideas first hand.
              I have something better in mind. I want Spring to generate application contexts based on a appcontext-template.

              With my last few projects a have a copy of a appcontext where only some parameters are changed. (I`m writing searchengines based on Lucene and Spring), but I want to generate the final app context based on some template.

              usage (in the main application context)
              Code:
              <bean id="personContextTemplateFactoryBean "class="ContextTemplateFactoryBean>
                   <property name="template" value="appContext-template.xml"/>
                  <property name="argMap">  
                        <map>
                              <entry key="name" value="person"/>
                        </map>
                  </property>
              </bean>
              Template:

              Code:
              <bean id="$&#91;name&#93;Dao" class="com.jph.$&#91;Name&#93;Dao"/>
              
              <bean id="$&#91;name&#93;Manager" class="com.jph.$&#91;Name&#93;Manager">
                   <bean id="dao" value="$&#91;name&#93;Dao"/>
              </bean>

              This example is not very good because this isn`t the normal. But with the last few projects it would love a template based runtime application context generator (Maybe based on Velocity)

              Comment

              Working...
              X