JavaEE solution configuration best practices

前端 未结 6 1942
余生分开走
余生分开走 2021-02-04 07:48

We build 3-tier enterprise solutions that typically consists of several webapp and ejbjar modules that all talk to a db and have several external integration points.

Eac

6条回答
  •  情话喂你
    2021-02-04 08:44

    Use multiple maven projects and continuous integration (eg. hudson or jenkins) to build a configuration jar that includes all the property files for each environment (dev, qa, prod) and then bundle everything up as an EAR. But then things can't be easily changed in production when needed.

    I think the config should be in the database of the application instance. Your local machine config may be diffrent to dev and to QA, PROD , DR etc.

    What you need is a way of getting the config out the database in a simple way.

    I create a separate project with a provided dependency of Apache commons-configuration It has many ways of storing data, but I like databases and the configurations lives in the database environment.

        import javax.sql.DataSource;
        import org.apache.commons.configuration.DatabaseConfiguration;
    
        public class MYConfig extends DatabaseConfiguration {
    
            public MYConfig(DataSource datasource) {
                super(datasource, "TABLE_CONFIG", "PROP_KEY", "PROP_VALUE");
            }
        }
    

    Put most of the settings in the DB and have a simple screen to modify it. Internally we can have a generic configuration service EJB that can read and modify the values. Each module can have a custom extended version that have specific getters and setter.

    Commons configurations as a simple API, you may then write the GUI as you wish. You can do the interface in anyway you wish. Or as a quick win have no interface.

    Version control all the property files then check it out on production and check it into a production branch after making changes.

    Version control is great. Add another DatabaseConfiguration using composition. The class you extends is the active config and the composed one being the audit. There is another constructor can can have a version. Just overload the right methods to get the desired effect.

        import javax.sql.DataSource;
        import org.apache.commons.configuration.DatabaseConfiguration;
    
        public class MYConfig extends DatabaseConfiguration {
            final DatabaseConfiguration audit;
    
            public MYConfig(DataSource datasource) {
                super(datasource, "TABLE_CONFIG", "PROP_KEY", "PROP_VALUE");
    
                audit = new DatabaseConfiguration("TABLE_CONFIG_AUDIT", "PROP_KEY", "PROP_VALUE");
            }
            @Override
            public void addProperty(String key, Object value) {
                Object wasValue = super.getProperty(key);
                super.addProperty(key, value); 
                audit.put(key,wasValue);//add version code
            }
        }
    

    http://commons.apache.org/proper/commons-configuration/

提交回复
热议问题