Giter Site home page Giter Site logo

org.spring.utils's Introduction

Common Spring Utils

Inject a property file into the Spring Environment. This is needed if you want to use properties from a file while importing xml in Spring managed beans xml files, like so:

<beans>
    <import resource="com/bank/service/${customer}-config.xml"/>
</beans>

The variable ${customer} should now be read from a variable.

According to a blog entry from spring (http://spring.io/blog/2011/02/15/spring-3-1-m1-unified-property-management/) this should be possible.

Unfortunately it does not work when you use a property-placeholder:

<context:property-placeholder ignore-resource-not-found="true" ignore-unresolvable="false" location="some.properties"/>

The file property resources are resolved after the xml imports are resolved.

Because of this you need to use a class, which registers a new ResourcePropertySource by hand into the application context. This can be done using the class "org.spring.common.utils.CustomApplicationContextInitializer" from this repository.

In a ServletContainer you can configure web.xml like so to use this class:

  <context-param>
    <param-name>contextInitializerClasses</param-name>
    <param-value>org.spring.common.utils.CustomApplicationContextInitializer</param-value>
  </context-param>
  <context-param>
    <param-name>propertiesFile</param-name>
    <param-value>/some/folder/some.properties</param-value>
    <!-- 
      Here you can also use spring variables like "file:${some.dir.variable}"
    -->
  </context-param>
  <!--
  <context-param>
    <param-name>propertiesFileLoadOrder</param-name>
    <param-value>FIRST|LAST</param-value>
  </context-param>
  This parameter controls the order in which the property file parameters are loaded.
  "FIRST": The parameters of the property file are loaded first and win against other sources (System, JVM, JNDI Parameters).
  "LAST":  The parameters of the property file are loaded last and loose against other sources (System, JVM, JNDI Parameters).

  An example: Parameter "myParameter" is passed in the JVM with "JVM Parameter" and saved in the property file with "Property File Parameter"
  "FIRST": "myParameter" is "Property File Parameter", because the value is first loaded from the property file.
  "LAST": "myParameter" is "JVM Parameter", because the value is last loaded from the property file and the JVM Parameter is loaded first.

  The default value is "FIRST".
  -->

Comments, questions and feedback are very welcome.

org.spring.utils's People

Contributors

jpfeiferpe avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.