Home | Tutorials | Smart-Cloud | Smart-EIS | License | FAQ | Contact

This section includes the user-guide of Smart-Cloud configurations.

Basic Usage

Create src/main/resources/config.properties file inside your root source folder, in case of maven projects, with the following sample contents:

#H2 Configurations
hibernate.connection.driver_class = org.h2.Driver
hibernate.connection.url = jdbc:h2:file:./h2db.data

#MySQl Config
#hibernate.connection.driver_class = com.mysql.jdbc.Driver
#hibernate.connection.url = jdbc:mysql://localhost:3306/app?createDatabaseIfNotExist=true

#Oracle Config, you will need to add oracle driver dependncy,
#checkout, option 4(System Path): https://www.mkyong.com/maven/how-to-add-oracle-jdbc-driver-in-your-maven-local-repository/

#hibernate.connection.driver_class = oracle.jdbc.driver.OracleDriver
#hibernate.connection.url = jdbc:oracle:thin:@localhost:1521/orclpdb1
#hibernate.c3p0.preferredTestQuery=SELECT 1 FROM DUAL

hibernate.connection.username = sa
hibernate.connection.password = sa

#To build tables from Entities
hibernate.hbm2ddl.auto=update
#Package to scan for JPA entities, CSV value is allowed for multiple packages
db-entities-packages=com.app

Config Initialization

Most likely the configuration will be auto loaded during the application startups using listeners. However, if for some reason you want to initialize it your self, the first call to JKConfig.getDefaultInstance() will auto configure it.

And to retrieve value from the configuration, use the following code:

String property = JKConfig.getDefaultInstance().getProperty("your-variable-name", "default value);

Configuration Order

In Smart-Cloud framework, the configuration is managed in several ways according to the following order:

  1. Load from test.config.properties file in the class path or current working directory.

  2. Load from CloudFoundery VCAP_SERVICES environment variable.

  3. It will look for environment variable with SMART_CLOUD name on the host server.

  4. Load the keys directly from host environment variables, for example, you can set the hibernate.connection.username as environment variable key, individually.

  5. It will look for a file named config.properties in the current working directory.

  6. It will look for file named config.properties in the root of classpath

  7. It will look for file named default.config.properties in the classpath or current working directory.

Load Config from Local Folder or Git Repository

If you would like to have other options for configurations, starting from 4.0.9, you can either specify a folder location on the application host server, or you can specify a Git repository to have your configurations per app.

You can do that by adding a pre.config.properties to your src/main/resources folder or in the current working directory of your project.

app.name=....
config.local.path=....
git-url=....
git-username=....
#git-password=.....
git-password-plain=.....

In your repository, you can have system.config.properties file as default configuration for all the apps in your applications, also you can specify the configuration per module by having a file named ${app.name}.config.properties where ${app.name} is the value of your app.name property in the pre.config.properties mentioned above.

For profiles, you can use git branches as profiles, for example, you can create dev,staging, and prod branches.

To have more flexibility and security, you can replace your config.properties or "pre.config.properties" during the CICD process to have the right configuration to avoid exposing production and other environments configurations to the wrong people.

Smart-Cloud configuration is based on Apache Commons Config, so you can use the system, constants, or environment variables as follows:

user.file = ${sys:user.home}/settings.xml
action.key = ${const:yourclass.CONSTANT_NAME}
java.home = ${env:JAVA_HOME}

Configurations Defaults:

If you don’t provide the configuration, defaults will be as follows:

Header Name Default Description

jk.app.name

If not set, framework will try to resolve to main class full qualified name

Your application name

hibernate.connection.driver_class

org.h2.Driver

H2 database driver

hibernate.connection.url

jdbc:h2:file:./h2db.data

File based database with name h2db.data in the current working directory

hibernate.connection.username

sa

default username of H2

hibernate.connection.password

sa

default password of H2

hibernate.dialect

org.hibernate.dialect.H2Dialect

This should be set based on your database, full list available at: Dialicts

db-entities-packages

com.app

The package names to scan for JPA entities. CSV value is allowed for multiple packages

Hibernate and C3P0 Defaults

Below are the default Hibernate configuration used by the framework. We use C3p0 connection pool implementation; Detailed configuration description be found at C3p0 Official Documentaion

Header Name Value Description

hibernate.hbm2ddl.auto

update

Create tables of not exists

hibernate.connection.autocommit

true

Default to Auto Commit

hibernate.show_sql

false

Show Generated SQL statement

hibernate.format_sql

true

hibernate.use_sql_comments

false

hibernate.globally_quoted_identifiers

true

hibernate.id.new_generator_mappings

false

hibernate.c3p0.min_size

1

hibernate.c3p0.initialPoolSize

1

hibernate.c3p0.max_size

4

hibernate.c3p0.acquire_increment

1

hibernate.c3p0.timeout

18000 (60 * 60 * 5 = five hours)

Release un-needed connections above the min-size

hibernate.c3p0.maxConnectionAge

24 hours

Force refreshing connections after this time even if busy, to ensure freshness

hibernate.c3p0.testConnectionOnCheckout

true

hibernate.c3p0.preferredTestQuery

SELECT 1

For oracle, use "Select 1 From Dual"

hibernate.c3p0.idleConnectionTestPeriod

300

If this is a number greater than 0, c3p0 will test all idle, pooled but unchecked-out connections, every this number of seconds

hibernate.c3p0.acquireRetryAttempts

3

hibernate.c3p0.acquireRetryDelay

3000

hibernate.c3p0.unreturnedConnectionTimeout

20

hibernate.c3p0.debugUnreturnedConnectionStackTraces

false

hibernate.c3p0.contextClassLoaderSource

none

jk.security.enabled

false

Enable spring security on smart-cloud-webstack

When password started with three under scores "_", the password will be considered encrypted, the decryption algorithm will remove the three hashes then decrypts the password.

Access Properties

Properties are all used internally by the framework, but if you need for any reason, you can access any property, use

Prior to versions 1-3, all the configuration was set on System properties, and could retrieved by:

System.getProperty(propertyName);

In version 4, it should be retrieved like this:

JKConfig.getDefaultInstance().getProperty(propertyName);

Home | Tutorials | Smart-Cloud | Smart-EIS | License | FAQ | Contact