Giter Club home page Giter Club logo

webapp-properties's Introduction

webapp-properties

Load Properties from a file into SystemProperties or as an Attribute in ServletContext, using WebappBaseName as reference in a servlet container like Tomcat. Open Source Java project under Apache License v2.0

Current Stable Version is 1.0.0


DOC

Installation:

  • Place webapp-properties-x.x.x.jar in tomcat/lib/

Configuration:

<!-- Context Listener for Servlet Container -->
<!-- tomcat/conf/web.xml or WEB-INF/web.xml -->
<listener>
	<description>Load Properties from a file into SystemProperties or as an Attribute in ServletContext, using WebappBaseName as reference</description>
	<listener-class>org.javastack.webappproperties.WebAppPropertiesContextListener</listener-class>
</listener>
Note: If you have more than one webapp per JVM and you are loading this to system-properties without SystemClassLoaderProperties the keys with same name can collide and view unexpected values. Properties as Attribute in ServletContext may be better alternative than Global System Properties.

Naming conventions and order of load:

  1. Default system properties (never overwrite existing property): {baseDir}/appconf/{webappBaseName}/system-properties-default.properties
  2. Forced system properties (always overwrite existing property): {baseDir}/appconf/{webappBaseName}/system-properties-forced.properties
  3. Context Attribute properties: {baseDir}/appconf/{webappBaseName}/context.properties
{webappBaseName} follow the Tomcat Basenames convention

Resolution order of {baseDir} (system property):

  1. org.javastack.webappproperties.conf
  2. catalina.base
  3. catalina.home
  4. user.dir
pick next system property if key is not defined.

Usage of Context Attribute properties:

final String CONST_CONTEXT_ATTRIBUTE_NAME = "org.javastack.webappproperties.ctx";
final Properties p = (Properties) getServletContext().getAttribute(CONST_CONTEXT_ATTRIBUTE_NAME);

MAVEN

<dependency>
    <groupId>org.javastack</groupId>
    <artifactId>webapp-properties</artifactId>
    <version>1.0.0</version>
    <scope>provided</scope>
</dependency>

Inspired in SystemClassLoaderProperties and CatalinaProperties, this code is Java-minimalistic version.

webapp-properties's People

Contributors

ggrandes avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

guoyu07

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.