All posts by Saurabh Gupta

My Name is Saurabh Gupta, Done MCA from MMMEC Gorakhpur and having approx. 12 Year of experience in Information Technology World manly in Java/J2EE. During this time I have worked with multiple organization with different client, so many technology, frameworks etc.

Gradle : Tasks


“A task is a piece of work that Gradle builds perform.”

Gradle Build script defined for one or more projects. Each project build is made up of multiple tasks. For Example:

  • Compiling classes
  • Storing classes to target
  • Copy files from resources to target.
  • Making Jar
  • Generating ]ava doc etc.

The Gradle build has common in-built tasks to build and run an application. You can also define your own tasks to customize the build process.

Topics Covered

  • Structure of Task
  • Define your Own Tasks
  • Define Default Task
  • Task Dependencies or Order
  • Use External Dependencies on Task
  • Dynamic Tasks
  • Execution of Tasks
  • Get the list of Gradle In-built tasks

Structure of Task

To define your own task in build.gradle, you need to use task keyword to define a custom task. Gradle follows this task structure :

task myTask{
   println 'Execute My Task' 
   
   doFirst{
    println 'Execute doFirst 2 with in MyTask' 
   } 
   doFirst{
    println 'Execute doFirst 1 with in MyTask' 
   }  

  doLast{
    println 'Execute doLast 1 with in MyTask' 
   } 
   doLast{
    println 'Execute doLast 2 with in MyTask' 
   }   
}

Herewith defining tasks you can also add behavior to existing tasks by implementing the actions. in the Gradle task, we can add doFirst or doLast or both actions. You will

    • doFirst: (Optional)

This action executes at the beginning of task execution.

    • doLast: (Optional)

This action executes at the end of the task execution.

doFirst and doLast can be added in task multiple times and execution of these all doFirst and doLast will be in sequence of implementation.

Output ->gradlew myTask -q

Execute My Task
Execute doFirst 1 with in MyTask
Execute doFirst 2 with in MyTask
Execute doLast 1 with in MyTask
Execute doLast 2 with in MyTask

Define Your Own Tasks

Gradle provides lots of ways to define these tasks as follows:

  1. Simple Declaration
    task myTask {
       doLast {
          println 'FacingIssuesOnIT'
       }
    }
  2. Define Task with Symbols use the symbol (<<) doLast or (>>) doFirst
    task myTask << {
       println 'FacingIssuesOnIT'
    }
  3. Alternate way with Symbol
    task (myTask) << {
       println 'FacingIssuesOnIT'
    }
  4. String Task Name
    task ('myTask') << {
       println 'FacingIssuesOnIT'
    }
  5. Define task by create() method
    tasks.create (name : 'myTask') << {
       println 'FacingIssuesOnIT'
    }

The above are ways to define tasks in Gradle. If you copy each way and try to execute a task with below command it will return the same result.

Output -> gradlew myTask -q

FacingIssuesOnIT

Define Default Task

You can define your default tasks in build.gradle file with keyword defaultTasks. These tasks will be executed when you have not specified any task for execution.

defaultTasks 'clean', 'run'

task clean {
    doLast {
        println 'Default System Cleaning!'
    }
}

task run {
    doLast {
        println 'Default Running!'
    }
}

task other {
    doLast {
        println "I am not a default task!"
    }
}

In this example mentioned default tasks as ‘clean’ and ‘run’. These tasks will execute when no task specified for execution. Let’s execute this command and see the output.
output:

Output -> gradlew -q

Default System Cleaning!
Default Running!

Output-> gradlew other -q

I am not a default task!

Task Dependencies and Order

Sometimes one task depends on other tasks and needs to define execution order of tasks. These task dependencies and task order are controlled by these methods:

  1. dependsOn: Use to add the given dependencies to this task.
    tasks.create('A')
    tasks.create('B').dependsOn('A')

    Executing B here require to execute task A first.

  2.  mustRunAfter: It defines the ordering of tasks.
    tasks.create('C')
    tasks.create('D').mustRunAfter('C')

    Execution of task D doesn’t require C but if both tasks are included for execution task C will execute first then task D.

  3.  shouldRunAfter : It’s also define ordering of tasks but not restrictive as above. This ordering ignored in two cases:
    1. If using that rule introducing a ordering cycle.
    2. If using parallel execution and all dependencies are satisfied except “should run after” then task will execute even it’s not satisfied “should run after” condition.

See Also: Gradle: Task Properties, Methods, and Actions

Example:  Here is an example to use dependsOn function to show dependencies of a task in build.gradle file.

task hello {
    doLast {
        println 'Hello!'
    }
}
task detail {
    dependsOn hello
    doLast {
        println "You are in 'Facing  Issues on IT'"
    }
}

In this example when run task detail then it’s dependent task hello will also execute.
Output

Output->gradlew detail -q

Hello!
You are in 'Facing  Issues on IT'

Note: Always define your task before use it. If not the following order you will get MissingPropertyException.

Use External Dependencies In Task

You can use buildScript function build.gradle to declare repositories and dependencies required for the task.

import org.apache.commons.codec.binary.Base64

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath group: 'commons-codec', name: 'commons-codec', version: '1.2'
    }
}

task encodeText {
    doLast {
        def byte[] encodedString = new Base64().encode('Facing Issues On IT\n'.getBytes())
        println 'Before Encode: Facing Issues on IT'
        println 'After Encodeing:' + new String(encodedString)
    }
}

In this example, for task encodeText is used Base64 class to encode text. So here you need to mentioned repositories and dependencies required to import the Base64 class

Output->gradlew encodeText -q

Before Encode: Facing Issues on IT
After Encodeing:RmFjaW5nIElzc3VlcyBPbiBJVAo=

Dynamic Tasks

By using Groovy or Kotlin scripting language, You can create tasks dynamically.

  1. Create a task by Loop
    This code will create 5 tasks by the loop (0 to 4). These task name as task0, task1, task2, task3, task4.
5.times { counter ->
    task "task$counter" {
        doLast {
            println "This is task number $counter"
        }
    }
}
task1.dependsOn task2, task3

Suppose to execute a particular task2 run command as

Output->gradlew task2 -q
This is task number 2

Output->gradle -q task1
This is task number 2
This is  task number 3
This is task number 1

Execution of Tasks

Here are different cases to execute tasks in gradle.

  • Execute Specific Task
    In all these above examples you have seen the below command to the execution of the task.

    gradlew taskName -q

    Here -q represents log level as QUIET which shows logs statement for  QUIET level and no verbose log statement. See Also : Gradle: Logging Configuration

  • Execute Default Task
    If no task specified then only default task will execute.

    gradlew  -q
  • Execute Multiple Tasks
    gradlew taskName1 taskName2 -q
  • Exclude Tasks
    Use –exclude-task to exclude tasks.

    gradlew taskName1 taskName2 --exclude-task test -q

    In this example test will not execute.

  • Execute Task in multi-Project build
    Use colon(:) to specify task related to sub project.

    gradlew mySubproject:taskName

Gradle In-built Tasks

Gradle is having a big list of in-built common tasks that not required any implementation. These can be executed by names only.

To get a list of all Gradle in-built tasks by executing the below command.

gradlew tasks --all

Here is a list of Gradle in-built tasks.

  • Build Tasks
    • assemble – Assembles the outputs of this project.
    • build – Assembles and tests this project.
    • buildDependents- Assembles and tests this project and all projects that depend on it.
    • buildNeeded – Assembles and tests this project and all projects it depends on.
    • classes – Assembles main classes
    • clean – Deletes the build directory.
    • jar – Assembles a jar archive containing the main classes
    • testClasses – Assembles test classes.
  • Build Setup Tasks
    • init – Initializes a new Gradle build.
    • wrapper – Generates Gradle wrapper files
  • Documentation tasks
    • javadoc – Generates Javadoc API documentation for the main source code.
  • Help tasks
    • buildEnvironment – Displays all buildscript dependencies declared in root project ‘GradleJavaLibrary
    • components – Displays the components produced by root project ‘GradleJavaLibrary’. [incubating]
    • dependencies – Displays all dependencies declared in root project ‘GradleJavaLibrary’.
    • dependencyInsight – Displays the insight into a specific dependency in root project ‘GradleJavaLibrary’.
    • dependentComponents – Displays the dependent components of components in root project ‘GradleJavaLibrary’. [incubating]
    • help – Displays a help message.
    • model – Displays the configuration model of root project ‘GradleJavaLibrary’. [incubating]
    • outgoingVariants – Displays the outgoing variants of root project ‘GradleJavaLibrary’.
    • projects – Displays the sub-projects of root project ‘GradleJavaLibrary’.
    • properties – Displays the properties of root project ‘GradleJavaLibrary’.
    • tasks – Displays the tasks runnable from root project ‘GradleJavaLibrary’.
  • Verification tasks
    • check – Runs all checks.
    • test – Runs the unit tests.
  • Other tasks
    • compileJava – Compiles main Java source.
    • compileTestJava – Compiles test Java source
    • prepareKotlinBuildScriptModel
    • processResources – Processes main resources.
    • processTestResources – Processes test resources.
  • Rules
    • Pattern: clean: Cleans the output files of a task.
    • Pattern: build: Assembles the artifacts of a configuration.
    • Pattern: upload: Assembles and uploads the artifacts belonging to a configuration.

References

[Solved] groovy.lang.MissingPropertyException: Could not get unknown property ‘A’ for task ‘:B’ of type org.gradle.api.DefaultTask.


groovy.lang.MissingPropertyException this exception occurred when gradle not able to find a property. Gradle check these properties in sequence as below if not find out throw this exception.

  • gradle.properties
  • System environment variables
  • command-line arguments to execute the build script
  • build.gradle

Example

Here is one example where defining two dependent tasks detail and hello. Where a detail task is dependent on hello task the same declared is by using dependsOn.

See Also: How to define Gradle tasks?

build.gradle


task detail {
    dependsOn hello
    doLast {
        println "You are in 'Facing  Issues on IT'"
    }
}

task hello {
    doLast {
        println 'Hello!'
    }
}

Exception Stackrace

Here executing Gradle task detail and using –stacktrace to print the complete stack trace of exception in the console to find out the root cause.

F:\Workspace-Gradle\MyGradleJavaProject>gradlew detail -q --stacktrace

FAILURE: Build failed with an exception.

* Where:
Build file 'F:\Workspace-Gradle\MyGradleJavaProject\build.gradle' line: 40

* What went wrong:
A problem occurred evaluating root project 'MyGradleJavaProject'.
> Could not get unknown property 'hello' for task ':detail' of type org.gradle.api.DefaultTask.

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'MyGradleJavaProject'.
        at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93)
        at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl$2.run(DefaultScriptPluginFactory.java:237)
        at org.gradle.configuration.ProjectScriptTarget.addConfiguration(ProjectScriptTarget.java:77)
        at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:242)
        at org.gradle.configuration.BuildOperationScriptPlugin$1$1.run(BuildOperationScriptPlugin.java:69)
..
...
...
Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'hello' for task ':detail' of type org.gradle.api.DefaultTask.
        at org.gradle.internal.metaobject.AbstractDynamicObject.getMissingProperty(AbstractDynamicObject.java:85)
        at org.gradle.internal.metaobject.ConfigureDelegate.getProperty(ConfigureDelegate.java:130)
        at build_ys26dll53lljjzslm0aousl9$_run_closure1.doCall(F:\Workspace-Gradle\MyGradleJavaProject\build.gradle:40)
...

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

Reason of Exception

Here is the problem statement as given in cause is “Could not get unknown property ‘hello’ for task ‘:detail’ of type org.gradle.api.DefaultTask.”. It means statement dependOn hello inside the task detail not able to find task hello. Because hello task definition is after detail task and execution of the script is from Top to Down so while execution hello task not recognized and throw an exception as MissingPropertyException.

Solution

Always define your tasks before going to use it. For the above example define hello task before detail task as below.

task hello {
    doLast {
        println 'Hello!'
    }
}
task detail {
    dependsOn hello
    doLast {
        println "You are in 'Facing  Issues on IT'"
    }
}

In this example when run task detail then it’s dependent task hello will also execute.
Output

-------->gradlew detail -q

Hello!
You are in 'Facing  Issues on IT'

If this solution helps you please write comments and for any Gradle related issue post it here.

Gradle: Dependency Management


The majority of Java projects are based on libraries (jars) i.e called project dependencies. To build java projects it’s required to configure and manage dependencies.

Dependency Management

To configure a dependency in a project required this information:

  1. Which dependency you need i.e(name and version)
  2. What it’s needed for i.e (compilation or run)
  3. Where to look for it .i.e (Repository)

Here first two things need to configure in dependencies {} section while the third point will configure in repositories {} section in build.gradle.

See Also: Gradle: Repositories Configuration

repositories {
     mavenCentral()
}
dependencies {
    //use for hibernate
    implementation 'org.hibernate:hibernate-core:3.6.7.Final'

    // Use JUnit test framework
    testImplementation 'junit:junit:4.12'
}

In this above example:

  • mavenCentral() is repository where gradle search for dependencies.
  • implementaion and testImplimation are scopes for dependencies which tell gradle to when these dependencies need to use.
  • junit:junit:4.12 is the ID of the dependency, In form of ‘<group>:<module>:<version>’ or ‘<groupId>:<artifactId>:<version>’ in maven terminology.

Scopes of Gradle Dependencies

Gradle provides lots of scopes to configure dependencies in projects.

Scope Description
compileOnly Use for dependencies those are required to compile your production code but that should not be part of the runtime classpath.
implementation (supersedes compile) Use for compilation and runtime.
runtimeOnly supersedes runtime) Use only at runtime, not for compilation
testCompileOnly It’s same as compileOnly for the tests
testImplementaion It’s the same as implementation for the tests.
testRuntimeOnly It’s the same as runtimeOnly for the tests.

Note: Java Library Plugin creates one more configuration – api – for dependencies that are required for compiling both modules and any modules depend on it.

Dependencies from Local File Systems

You can also set dependencies from local file system or from lib folder.

Dependencies from Project lib folder

dependencies {
    // for specific jars
    runtime files('libs/library1.jar', 'libs/library2.jar')
    //for all jars in lib folder
    runtime fileTree(dir: 'libs', include: '*.jar')
}

Dependencies from Local Machine

dependencies {
    compile fileTree(dir: "${System.properties['user.home']}/libs/banks", include: '*.jar')
}

References

https://docs.gradle.org/current/userguide/building_java_projects.html

Gradle : Repository Configuration


In Gradle, build.gradle file specifies repositories to search dependencies of projects. Gradle support repositories configuration for Ivy and Maven.

Maven Repository

You can configure maven repositories in Gradle in multiple ways:

  1. Maven Central Repository
    repositories {
        mavenCentral()
    }
  2. Maven Repository by  Target URL
    repositories {
        maven {url "http://repo.myoffice.com/maven2"}
    }
  3. Maven Repository for Other Target       For example Bintray as Maven repository
    repositories {
        maven ("http://jcenter.bintray.com/")
    }

Ivy Repository

You can also set Ivy repository as below.

repositories {
    ivy { url "http://repo.mycompany.com/repo"}
}

Dependencies from Multiple Repositories

You can add multiple dependencies at once.

repositories {
   maven ("https://repository-engine.forge.cloudbees.com/snapshot/")
   jcenter {
      url "http://jcenter.bintray.com/"
   }
}

Now you have learned about the ways to configure Gradle repositories in build.gradle file to search dependencies. In case if you want to use dependencies from your local file system you can figure that also in the dependencies section. Check Gradle: Dependencies Configuration to know more about it.

Gradle : Logging Configuration


Gradle is very rich with logging configuration options for log level, formatting and error stacktrace handling etc.

Gradle logging configuration is required to debug build failure, task execution status and sequence of execution of tasks to build and run projects. It’s formatting style and colors highlight option make build failure debugging easy to understand and resolve issues.

Topics Covered

  • Gradle Log Level Configuration
  • Write Your Own Log Message
  • Gradle Stacktrace Options
  • Gradle Console Log Formatting
  • Gradle Warning Display Options

Gradle Log Level Configuration

Gradle support following log level options, It ordered from least verbose (–debug) to most most verbose (–quiet). Gradle default log level is Lifecycle.

Options Description
-q , –quiet Set Gradle log level QUIET to print errors only.
-w , –warn Set Gradle log level WARN to print warnings and errors.
-i , –info Set Gradle log level INFO to print info, warning and errors.
-d , –debug Set Gradle log level DEBUG to print debug, info, warning and errors.
No Log Option Default log level LIFECYCLE once you not set any. It prints gradle life cycle all statements to execute a task..

There are multiple ways to set Gradle Log Level based on your need:

Set property in gradle.properties in your project root folder or in you GRADLE_HOME folder.

org.gradle.logging.level=debug

or Set Gradle environment variable.

-Dorg.gradle.logging.level=debug

or Pass Gradle log level option on time of execution of tasks. For Example: Passing log level as -w to print logs for warning or errors.

gradlew [task]-w

For Example:

Now takes reference of previous, Gradle Multi Project Application and execute gradle build with out any log level (Default log level is LIFECYCLE)  and builds got executed successfully but not printed any task execution steps.

Gradle multi project build after include sub project

I will take reference of same example for further log settings.

Write Your Own Log Messages

Gradle supports many ways to write your own Log messages in build.gradle file.

  1. Write Log Message by stdout: By default logged these message at QUIET level.
    println 'Logged message at QUIET level'
    
  2. Write Log Message by Logger property: Gradle provide logger property to write message on different log level.
    logger.quiet('Always Logged an info log message.')
    logger.error('Logged an error message.')
    logger.warn('Logged  a warning message.')
    logger.lifecycle('Logged  a lifecycle info message.')
    logger.info('Logged an info message.')
    logger.debug('Logged a debug message.')
    logger.trace('Logged a trace message.')
    
  3.  Write Log Message with place holder: Use curly braces ({}) for place holder.
    logger.info('Test a place holder {} log message', 'info')
    

Now for test your log level configuration. Write these state debug statements in your build.gradle file.

//top level log stdout
println 'Logged message at QUIET level'
 
task logInfo {
    //task debug
    logger.quiet('Always Logged an info log message.')
    logger.error('Logged an error message.')
    logger.warn('Logged  a warning message.')
    logger.lifecycle('Logged  a lifecycle info message.')
    logger.info('Logged an info message.')
    logger.debug('Logged a debug message.')
    logger.trace('Logged a trace message.')
    
    //test place holder
    logger.info('Test a place holder {} log message', 'info')
}

Run these command on console and verify your results.

Gradle Log Level

In above example, running specific logInfo task to check our configuration. Based on passing log level option it’s showing log statements in console.

Gradle Stacktrace Options

By default Gradle doesn’t print stacktrace in logs if case build get fail. To enable stacktrace use these options.

Options Description
-s or –stacktrace Use this option when need to get truncated stacktrace. It reduces the unnecessary verbose statements.
-S or –full-stacktrace Use this option when need print complete stacktrace and it’s also print stacktrace for deprecated warnings.

Gradle Console Log Formatting

Gradle is rich with console log formatting.  Gradle console mode provide some additional features while build and run:

  • Use colors and fonts to highlight log level, important outputs and errors.
  • Show Progress lines and what execution is going currently.
  • Progress bar and timer describe the overall execution status.
Options Description
plain This option disable all color and rich output in console log output. This is consider as default option when Gradle not attached to a terminal.
auto This is default option to enable color and other rich output when attached to a terminal.
rich This provide rich output in form of color, fonts and also support ANSI control characters.
verbose It’s use to enable color and other rich output like the rich, but print task names and out comes at the lifecycle log level.

There are multiple ways to set Gradle console log formatting options as below:

Set property in gradle.properties in your project root folder or in you GRADLE_HOME folder.

org.gradle.console=plain

or Set as system environment variable from command prompt.

-Dorg.gradle.console=plain

To pass Gradle console log  option on time of execution of tasks. For Example :Here by default log level is ‘–lifecycle’  and set console log option as plain (‘–console=plain’) to print logs console..

gradlew [task]--console=plain

Now build same previous, Gradle Multi Project Application with console option as ‘–console=plain’ and see the difference it’s printing all steps followed for execution of tasks.

Multi project all task in console

As an assignment you can try below line of statements to test different log level and see console outputs.

//Log Level as debubg
gradlew [task] -d --console=plain
//Log Level as info
gradlew [task]-i --console=plain

Gradle Warnings Display Options

Gradle doesn’t show warnings (e.g deprecated warnings) in sequence . Gradle collects all warnings and show a summary at end of builds:

For Example

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.

Gradle provides these options to show/ hide warnings in console log.

Options Description
all To log all warnings.
fail To log all warnings and fails in build.
summary To log summary suppress all warnings at end of build.
none To suppress all warnings and summary at end of build.

Gradle provides multiple ways to set property to show/hide gradle warnings:

Set property in gradle.properties in your project root folder or in you GRADLE_HOME folder.

org.gradle.warning.mode=all

or Set property as gradle environment variable.

-Dorg.gradle.warning.mode=all

or Pass warning mode on time on execution of task.

gradlew [task] --warning-mode=all

Conclusion

Here you have learn about gradle log level  configuration on project , tasks and centralize level. Here are these options:

  • Gradle Log Level:  Use these  different log level to debug gradle build.
    org.gradle.logging.level=debug|info|warn|quit
    
  • Gradle Stacktrace Options: Use -s for truncated stacktrace and -S for full stacktrace.
  • Gradle Console Log Formatting: For  formatted colored logs and  get execution progress status use  these console log options.
    org.gradle.console=plain|auto|rich|verbose
    
  • Gradle Warning show/hide: Use these  options for show and hide warnings.
    org.gradle.warning.mode=all|fail|summary|none
    

Gradle: Plugin Configuration in Eclipse or STS


Gradle Configuration in Eclipse or STS (Spring Tool Suite)

  • Step 1: Open Eclipse or STS IDE
  • Step 2: Go to Help -> Install from Market Place.
  • Step 3: Search for Gradle
  • Step 4: Select the option “Buildship Gradle Integration “.
  • Step 5: Click on the Installation button as in the below screen.

    Gradle Plugin Configugration in Eclipse or STS

  • Step 6: Navigate to the next screen. Select “I accept terms and license agreements
  • Step 7: Click on the Finish button.
  • Step 8: Click on Confirm and then your IDE will get started.
  • Step 9: Go to File -> Projects -> Search for Gradle.
  • Step 10: You will see the below screen.

Gradle Project in Eclipse

Here you have learned about the configuration of the Gradle plugin in Eclipse and STS (Spring Tool Suite).

See Also:

If this blog helps you or any issue facing related to Gradle drop comments to us.

Gradle : Installation On Linux and Mac


Gradle can be installed on an and run on any  Operating System and it required JDK and JRE installed on your machine.

Gradle Current Version: Gradle 6.3

Gradle Pre-Requisites

Your machine should have Java 8 or later versions of it.

java -version

if Java 8 is not installed and configured follow these steps in link: How to set java path of JDK/JRE?

Gradle Installation On Linux or Mac

  •  Download the latest Gradle Binary distribution for Linux  or Mac OS from this link: https://gradle.org/releases/
  •  Create a Gradle folder and unpack the zip file in this folder
    $ mkdir /opt/Gradle
    $ unzip -d /opt/Gradle gradle-6.3-bin.zip
    $ ls /opt/Gradle/gradle-6.3
    LICENSE  NOTICE  bin  getting-started.html  init.d  lib  media
  • Configure Your System Environment: Set PATH environment variable to include bin directory of unzipped Gradle.
    $ export PATH=$PATH:/opt/Gradle/gradle-6.3/bin
  •  Verify the Gradle installation and configuration by running below the Gradle command in the console.
    gradle -v
    ------------------------------------------------------------
    Gradle 6.3
    ------------------------------------------------------------

Here you have learned about Gradle installation and configuration in Linux and Mac OS. If you are facing any Gradle issue share your comments.

References

Gradle : Installation On Windows


Gradle can be installed on an and run on any  Operating System and it required JDK and JRE installed on your machine.

Gradle Current Version: Gradle 6.3

Gradle Pre-Requisites

Your machine should have Java 8 or later versions of it.

java -version

Java Version

if Java 8 is not installed and configured follow these steps in link: How to set java path of JDK/JRE?

Gradle Installation on Windows

  •  Download the latest Gradle Binary distribution from this link: https://gradle.org/releases/
  •  Unzip the downloaded zip file.
  • Create a folder like C:/Gradle and copy the unzipped folder in this location.
  • Set path environment variable for Gradle by using these steps:  Go to File Explorer -> right-click on This PC or (My Computer) icon -> click on Properties -> Advance System Settings ->Environment Variables.  Under System variable, select path property and then click on the edit button, then append this path C:\Gradle\gradle-6.3\bin as below and save it.Gradle Installation and Configuration in Windows
  •  Verify the Gradle installation and configuration by running below the Gradle command in the console.
    gradle -v

    Gradle Version

Here you have learned about Gradle installation and configuration in windows. If you are facing any Gradle issue share your comments.

References

[Solved] org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: smtps://smtp.gmail.com:465?XYZ due to: There are 2 parameters that couldn’t be set on the endpoint. Check the uri if the parameters are spelt correctly and that they are properties of the endpoint.


org.apache.camel.ResolveEndpointFailedException throws when an endpoint is not resolved by URI. It can happen because of formatting, escaping characters of the keyword are not used properly.

Camel Route Definition for SMTP Email

Here is the configured Camel route definition for SMTP email. Which is written as from one Gmail account to another email like to, CC and BCC.


String recipients = "&To=camel123@riders.org,easy123@riders.org&CC=me@you.org&BCC=someone@somewhere.org";
from("direct:a").to("smtps://smtp.gmail.com:465?username=job4saurabh@gmail.com&password=XYZ@123" + recipients);

Exception Stacktrace

As the exception cause described it’s because of unknown parameters CC and BCC. As for Camel Route Definition recognized all keywords in small letters.

 
org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> To[smtps://smtp.gmail.com:465?username=job4saurabh@gmail.com&password=XYZ@123&to=camel123@riders.org,easy123@riders.org&CC=me@you.org&BCC=someone@somewhere.org] <<< in route: Route(route1)[From[direct:a] -> [To[smtps://smtp.gmail.com:x... because of Failed to resolve endpoint: smtps://smtp.gmail.com:465?BCC=someone%40somewhere.org&CC=me%40you.org&password=xxxxxx&to=camel123%40riders.org%2Ceasy123%40riders.org&username=job4saurabh%40gmail.com due to: Failed to resolve endpoint: smtps://smtp.gmail.com:465?BCC=someone%40somewhere.org&CC=me%40you.org&password=xxxxxx&to=camel123%40riders.org%2Ceasy123%40riders.org&username=job4saurabh%40gmail.com due to: There are 2 parameters that couldn't be set on the endpoint. Check the uri if the parameters are spelt correctly and that they are properties of the endpoint. Unknown parameters=[{BCC=someone@somewhere.org, CC=me@you.org}]
    at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:390)
    at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:112)
    at org.apache.camel.impl.DefaultModel.start(DefaultModel.java:356)
    at org.apache.camel.impl.DefaultModel.startRoute(DefaultModel.java:330)
    at org.apache.camel.impl.DefaultModel.startRouteDefinitions(DefaultModel.java:323)
    at org.apache.camel.impl.DefaultModel.startRouteDefinitions(DefaultModel.java:302)
    at org.apache.camel.impl.AbstractModelCamelContext.startRouteDefinitions(AbstractModelCamelContext.java:326)
    
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: smtps://smtp.gmail.com:465?BCC=someone%40somewhere.org&CC=me%40you.org&password=xxxxxx&to=camel123%40riders.org%2Ceasy123%40riders.org&username=job4saurabh%40gmail.com due to: Failed to resolve endpoint: smtps://smtp.gmail.com:465?BCC=someone%40somewhere.org&CC=me%40you.org&password=xxxxxx&to=camel123%40riders.org%2Ceasy123%40riders.org&username=job4saurabh%40gmail.com due to: There are 2 parameters that couldn't be set on the endpoint. Check the uri if the parameters are spelt correctly and that they are properties of the endpoint. Unknown parameters=[{BCC=someone@somewhere.org, CC=me@you.org}]
    at org.apache.camel.impl.engine.AbstractCamelContext.getEndpoint(AbstractCamelContext.java:828)
    at org.apache.camel.impl.engine.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:130)
    at org.apache.camel.reifier.SendReifier.resolveEndpoint(SendReifier.java:42)
    at org.apache.camel.reifier.SendReifier.createProcessor(SendReifier.java:35)
    at org.apache.camel.reifier.ProcessorReifier.makeProcessor(ProcessorReifier.java:787)
    at org.apache.camel.reifier.ProcessorReifier.addRoutes(ProcessorReifier.java:513)
    at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:388)
    ... 35 common frames omitted
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: smtps://smtp.gmail.com:465?BCC=someone%40somewhere.org&CC=me%40you.org&password=xxxxxx&to=camel123%40riders.org%2Ceasy123%40riders.org&username=job4saurabh%40gmail.com due to: There are 2 parameters that couldn't be set on the endpoint. Check the uri if the parameters are spelt correctly and that they are properties of the endpoint. Unknown parameters=[{BCC=someone@somewhere.org, CC=me@you.org}]
    at org.apache.camel.support.DefaultComponent.validateParameters(DefaultComponent.java:358)
    at org.apache.camel.support.DefaultComponent.createEndpoint(DefaultComponent.java:261)
    at org.apache.camel.impl.engine.AbstractCamelContext.getEndpoint(AbstractCamelContext.java:780)
    ... 41 common frames omitted

Exception Reason

Apache Camel through this exception because of endpoint for URI is not resolved because of case-sensitive keywords. As here we are using BCC and CC as in capital letters while Apache camel allowed all keywords in small letters only.

Solution

Use keyword BCC and CC in small letters as defined in below camel route definition.


String recipients = "&To=camel123@riders.org,easy123@riders.org&cc=me@you.org&bcc=someone@somewhere.org";
from("direct:a").to("smtps://smtp.gmail.com:465?username=job4saurabh@gmail.com&password=XYZ@123" + recipients);

You can check all list of keywords for apache camel routes for SMTP in below list:
https://people.apache.org/~dkulp/camel/mail.html

Reference

https://www.javadoc.io/doc/org.apache.camel/camel-core/2.15.0/org/apache/camel/ResolveEndpointFailedException.html

[Solved] org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route(route1)[From[sendEmail] -> [To[smtps://smtp.gmail.com:… because of No endpoint could be found for: sendEmail, please check your classpath contains the needed Camel component jar.


org.apache.camel.FailedToCreateRouteException exception happens in Camel while creating a route but not able to create it because of some dependency missing for configuring the SMTP camel route for sending an email.

Camel SMTP Route Configuration

Here is Camel Route Definition for sending email.


String recipients = "&to=camel123@riders.org,easy123@riders.org&cc=me@you.org&bcc=someone@somewhere.org";
        from("direct:a").to("smtps://smtp.gmail.com:465?username=job4saurabh@gmail.com&password=XYZ@123" + recipients); 

 

Exception StackTrace

This exception happen at runtime because of required dependency missing.


2020-04-08 13:47:00 - Error starting CamelContext (camel-1) due to exception thrown: Failed to create route route1: Route(route1)[From[sendEmail] -> [To[smtps://smtp.gmail.com:... because of No endpoint could be found for: sendEmail, please check your classpath contains the needed Camel component jar.
org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route(route1)[From[sendEmail] -> [To[smtps://smtp.gmail.com:... because of No endpoint could be found for: sendEmail, please check your classpath contains the needed Camel component jar.
    at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:118)
    at org.apache.camel.impl.DefaultModel.start(DefaultModel.java:356)
    at org.apache.camel.impl.DefaultModel.startRoute(DefaultModel.java:330)
    at org.apache.camel.impl.DefaultModel.startRouteDefinitions(DefaultModel.java:323)
    at org.apache.camel.impl.DefaultModel.startRouteDefinitions(DefaultModel.java:302)
    at org.apache.camel.impl.AbstractModelCamelContext.startRouteDefinitions(AbstractModelCamelContext.java:326)
    at org.apache.camel.impl.engine.AbstractCamelContext.doStartCamel(AbstractCamelContext.java:2679)
    at org.apache.camel.impl.engine.AbstractCamelContext.lambda$doStart$2(AbstractCamelContext.java:2527)
    at org.apache.camel.impl.engine.AbstractCamelContext.doWithDefinedClassLoader(AbstractCamelContext.java:2544)
    at org.apache.camel.impl.engine.AbstractCamelContext.doStart(AbstractCamelContext.java:2525)
    at org.apache.camel.spring.boot.SpringBootCamelContext.doStart(SpringBootCamelContext.java:43)
Caused by: org.apache.camel.NoSuchEndpointException: No endpoint could be found for: sendEmail, please check your classpath contains the needed Camel component jar.
    at org.apache.camel.support.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:59)
    at org.apache.camel.impl.engine.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:123)
    at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:367)
    at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:112)
    ... 57 common frames omitted

Exception Reason

As Camel support multiple type of routing and it required dependcies for use it. Here we are using SMTP routing to send email on came of defined routing but it required to add camel dependency for SMTP email in pom.xml.

Solution

As exception stack trace clearly explained, it required missing camel component jar. In case of SMTP you need to add below jar for sending Email through camel SMTP route.


           <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-mail</artifactId>
            <version>${camel.version}</version>
        </dependency>

Java : Array & Arrays Class


In this post we will discuss about Java Array and Arrays class to deal with array and perform different operation by  API’s.  Initially will discuss about Array for understanding and once you will get knowledge of Array then end of this post will discuss about Arrays API’s with examples.

“Array is collection (or group of) of homogeneous (same data type) items  referred to single variable, which store in contiguous space in memory.”

Note : Java works differently then they do in C/C++, In Java array elements are not stored in continuous locations.

For example: You have 10 integer numbers and want minimum, maximum and  average of these numbers. One way is take 10 variables and perform comparison and operations of these numbers. If numbers are in hundreds very difficult to deal with that because need to handle 100 variables. That’s what array come on picture to deal with same type data.

See Also: Java: Arrays vs Collections

Points to remember:

  • Array always keep elements of same type such as primitive type or objects.
  • Array in Java array is dynamically allocated.
  • Array size always specified in int value not in short or long.
  • If number of elements in array are n ,then indexing of array start from 0…n-1.
  • Array is object in Java , if need to find  length, check for member length. To check length of array in C/C++ use sizeof.
  • Array can be use as static field, a local variable or a method parameter.
  • In java direct super class of Array is Object and implements java.lang.Cloneable and java.io.Serializable interface.
  • Time Complexity Access : Θ(1)
  • Time Complexity Search : Θ(n)
  • Time Complexity Insertion : Θ(n)
  • Time Complexity Deletion : Θ(n)
  • Space Complexity: O(n)

In data structure array are two types:

  • One dimensional arrays
  • Multi dimensional arrays

One Dimensional Array

One dimensional array also called as linear array.

Single Dimentional Array

Declaration of Array

Declaration show the reference of values as array and each value in array specified as type.

type var-name [];
or
type [] var-name;

Example to declare array of different types.

// both are valid way of declarations
int numbers[];
or int[] numbers; 

byte byteArr[];
short shortsArr[];
boolean booleanArr[];
long longArr[];
float floatArr[];
double doubleArr[];
char charArr[];
//array of reference objects of Class Type MyTestClass
MyTestClass myClassArray[]; 

//Array of unknown type object, as oBject is super class of class class
Object[]  objectArr,
//Array of unknown type of collection as Collection is super interface in Collection framework
Collection[] callectionArr;

Instantiation of Array

On array declaration only the reference of array created, to allocate memory to array need specified the size of array as below. where the size is always a integer value greater than zero.


var-name = new type[size];

For Example:

int numbers[]; //declaration
numbers=new int [10];//create an instance of array of 10 numbers.

Object[] objectArr; //declaration

objectArr=new Object[10]; //create an instance of array of 10 Objects.

Note:

  • For primitive type array instantiation, array elements values by default initialize with specified primitive default value. For example : primitive type int default value is 0, all the  elements array by default initialize with 0.
  • For reference type array instantiation, array element values by default initialize with specified primitive default value. For example : reference type Object default value is null, all the  elements array by default initialize with null.

Array Instantiation with Literals

If you already know the elements of an array , use literals in array to instantiation and assignment of values at same time.

//Array with int literals
int [] numbers={10,, 50, 70 , 90, 80};
//Array with String literals
String [] names= {"Saurabh", "Gaurav", "Raghav"};

Accessing of array

To access/assign the elements of an array, use index position within range 0 to n-1 for the size of array length n. If trying to access array beyond this range (0…n-1) for primitive and reference type, get an exception as ArrayIndexOutOfBoundException in case of String will throw StringIndexOutOfBoundsException

//accessing/assign value on array
arrName[index];

Example

//access value from array on index position 2, will result 70
int number=numbers[2];

//Assign value on index position , new change value 80
numbers[2]=80;

Java Program for Single Dimensional Array

Here is example of single line array , considering all above cases;


public class OneDimentionalArray {

	public static void main(String[] args) {

		//declaration by both ways
		int numbers[];

		//Instantion for array of int type size 10
		//By default initialize with 0 for primitive type int
		numbers=new int[10];

		//instantition with literals
		String []names= {"Saurabh","Gaurav","Raghav"};

		System.out.println("Print Numbers :");
		//access array with for loop
        for(int i=0; i<=numbers.length-1;i++)
		{
			System.out.println(numbers[i]);
		}

		System.out.println("\nPrint Name :");
		//access array with for each loop
		for(String name:names)
		{
			System.out.println(name);
		}

		// Assign values to Arrays by for loop
		for(int i=0; i<=numbers.length-1;i++)
		{
			numbers[i]=i*10;
		}

		//manually assign values,Raghav will replace with Ramesh
		names[2]="Ramesh";

		System.out.println("\n\nUpdate Values from arrays");

		//access array with for loop
                for(int i=0; i<=numbers.length-1;i++)
		{
			System.out.println(numbers[i]);
		}

		System.out.println("\nPrint Name :");
		//access array with for each loop
		for(String name:names)
		{
			System.out.println(name);
		}

	}

}

Output

Print Numbers :
0
0
0
0
0
0
0
0
0
0

Print Name :
Saurabh
Gaurav
Raghav

Update Values from arrays
0
10
20
30
40
50
60
70
80
90

Print Name :
Saurabh
Gaurav
Ramesh

Multi Dimensional Array

Multi-dimensional arrays also called Jagged Arrays, are arrays of arrays with each element of the array holding the reference of another array. A multi-dimensional array is created by appending square brackets ([]) per dimension.
For Example

int[][] intArr=new int [2][3]; //2D array
int numbers[][][]=new int [2][3][4]; //3D array

//2D representation with literals
//Create an array of size [2][3] and assign given values
int [][]numbers ={{2,5,7},{4,6,9}}

Two Dimentional Array

Java Program for Two Dimensional Array


public class TwoDimentionalArray1 {

	public static void main(String[] args) {

		//declaration
		int numbers[][] = {{2,5,7},{4,6,9}};

		//access in array of two dimensional array
        for(int i=0; i<=numbers.length-1;i++)
		{
        	for (int j=0; j<numbers[i].length;j++)
			System.out.println("numbers["+i+"]["+j+"]="+numbers[i][j]);
		}

		System.out.println("\n\nUpdate Values from arrays");

		numbers[0][1]=20;
		numbers[1][2]=30;
		numbers[0][0]=40;

		for(int i=0; i<=numbers.length-1;i++)
		{
        	for (int j=0; j<numbers[i].length;j++)
			System.out.println("numbers["+i+"]["+j+"]="+numbers[i][j]);
		}
	}

}

Output

numbers[0][0]=2
numbers[0][1]=5
numbers[0][2]=7
numbers[1][0]=4
numbers[1][1]=6
numbers[1][2]=9

Update Values from arrays
numbers[0][0]=40
numbers[0][1]=20
numbers[0][2]=7
numbers[1][0]=4
numbers[1][1]=6
numbers[1][2]=30

 

SOLID Software Design Principle


Why Software Design Principles?

Software Design principles are a set of guidelines to handle complexity and reduce the effort needed to develop a good system design. Design principles ease problems of future development, enhancement, maintenance and also reduce the scope of error during design.

SOLID Design Principles

What are Software Design Principles?

These are around 12  Software Design Key Principles but most important is SOLID Software Design principles. which use in all software designing.

  1. Single Responsibility Principle: One class should do one thing and do it well.
  2. Open Close Design Principle: Open for extension, close for modification.
  3. Liscov Substitution Principle: Subtype must be a substitute for supertype.
  4. Interface Segregation Principle: avoid monolithic interface, reduce pain on the client-side.
  5. Dependency Inversion Principle: Don’t ask lets framework give it to you.

1: Single Responsibility Principle (SRP)

A class should have only one reason to change. If there is any other reason to create another class.

This principle is completely based on Coupling and Cohesion. This principle states that your software design classes should in such a way that each class should have a single purpose/responsibility/functionality.

While designing software if you put more than one functionality in a single class then increase coupling between functionalities. If change required in one functionality there are chances to broke other functionality and required more testing to avoid such surprises in the production environment.

Responsibility Examples

Suppose you are having JPA classes as SavingAccountRepository.java and CurrentAccountRepository.java then SavingAccountRepository.java class should have only methods and queries related with Saving Accounts. It means your class should specialize in a single purpose.

Others most common example of responsibilities:

  • Logging
  • Formatting
  • Validation
  • Notification
  • Error Handling
  • Parsing
  • Caching
  • Mapping
  • Class Section/ Instantiation etc.

Benefits

  • This principle makes your software easier to implement and prevent unexpected side-effects of future changes.
  • Your class will change only if anything will change in respected responsibility.
  • Need to update dependencies and compile when some respected dependencies change.
  • Reduce coupling between software and components.

The Single Responsibility Principle (SRP) also provides other benefits with classes, components, and microservices with single responsibility to make your code easier to explain, understand, implement. It also improves development speed and easier to track bugs.

2: Open-Closed Principle (OCP)

Software entities like classes, modules, and functions should be open for extension (new functionality) and closed for modification.

This principle is based on inheritance or composition design patterns like Strategy Design pattern. As per this principle:

  • “Open” means, Your code should be able to extend existing code in order to introduce new functionality.
  • “Close” means, Once your module has been developed and tested, the code will change only when correct bugs.

For Example, A BankAccount.java base class contains all basic transaction-related properties and methods. The same class can be extended by SavingAccount.java and CurrentAccount.java to handle saving and current account functionalities. If new functionalities need to add then only modification required in BankAccount.java class. Hence this class is open for extension and close for modification.

Benefits

The main benefit of the Open/Close Design principle is that already developed and tested code will not be modified and don’t break.

3: Liscov Substitution Principle (LSP)

The driven type must be completely substituted for their base type.

Liscov Substitution Principle is closely related to the Single Responsibility Principle and Interface Segregation Principle.

This principle states that Subclasses or derived classes should be completely substituted by the superclass. The Subclass should enhance the functionality but not reduce it.

In other words, functions that use pointers and reference of base classes must be able to use objects derived classes without knowing it.

Example

Suppose Employee class extends Person Class by inheritance. In this way wherever you are using person class should also be able to use Employee class because Employee is a subclass of Person class.

Benefits

  • If this principle violates then so much extra conditional code of type checking and duplicate code need to write throughout the application that can cause bugs when the application grows.
  • In methods or functions which use the superclass type must work with the object of subclass without any issue.

4: Interface Segregation Principle (ISP)

Clients should not be forced to depend on methods in interfaces that they don’t use.

This principle states that a client should not implement an interface if it doesn’t use that. An interface should belong to clients, not to the library or hierarchy and keep only those methods as required for the client.

Example

In an application service interface exposed to the client should have only those methods that are related to the client.

Benefits

If you violate this principle and add some more methods in an interface that are not used with the client then if you change anything in interface definitely some functionality of the client will break.

5: Dependency Inversion Principle (DIP)

The high-level module should not depend on low-level module, both should depend on abstractions. Abstraction should not depend on detail. detail should depend on abstraction.

This principle provides loose coupling between the dependencies of modules and classes.

The Dependency Inversion Principle states that:

High-level modules should not depend on low-level modules directly, both should depend on abstractions. This abstraction should not depend on details, details should depend on abstractions.

Examples

The best example of the Dependency Inversion Principle is the Spring framework where dependencies are injected through XML or Annotation which provide abstractions and can change without modification on implementation.

Benefits

  • If you violate this principle your code will be tightly coupled because every high-level module is directly referencing to lower-level modules.
  • Makes testing easy by injecting the mock objects without modification on existing functionality.

Spring Boot: Common Properties and Default Value


Spring Boot comes with lots of default configuration that’s already defined in its application.propertie internal file. When we use spring-boot-starter-parent that’s add all these spring boot default properties in your application.

If your business required change on these default values then you can override it by writing in your application.properties/application.yaml file. On-time on initialization for application properties spring boot will override these default values with your mentioned configuration.

In the previous example, we are using the default spring boot embedded tomcat server port as 8080. It means when we launch our spring boot application embedded server will start on port 8080. Now for changing the embedded tomcat server port add this below property in your application.properties file.


server.port=8090

Now run this spring boot application example, because now embedded tomcat server is running on port 8090 so calling your application services now you have to use port 8090 instead of 8080.

Spring Boot Common properties with Default Value

For better understanding, I have categorized list of Spring Boot common properties in different categories so that you can focus as per your need.

Note: In your application, You don’t need to add all these values in your application.proprties/application.yaml file. You just need to add only those values which you want to change/override.

References

https://docs.spring.io/spring-boot/docs/1.4.x/reference/html/common-application-properties.html

Spring Boot: Data Configuration Properties and Default Value


These are Spring Boot Data properties that can be configured with any Spring Boot Application. These properties are already configured in Spring Boot with the given default value.

Note: In your application, You don’t need to add all these values in your application.proprties/application.yaml file. You just need to add only those values which you want to change/override.

See Also:

DAO Configuration Properties

Spring Boot load these properties in PersistenceExceptionTranslationAutoConfiguration class.

Name Default Value Description
spring.dao.exceptiontranslation.enabled true Enable the PersistenceExceptionTranslationPostProcessor.

DataSource Configuration Properties

Spring Boot load these properties in DataSourceAutoConfiguration & DataSourceProperties class.

Name Default Value Description
spring.datasource.continue-on-error false Do not stop if an error occurs while initializing the database.
spring.datasource.data Data (DML) script resource reference.
spring.datasource.data-username database usename to execute DML scripts (if different).
spring.datasource.data-password database password to execute DML scripts (if different).
spring.datasource.dbcp.* Commons DBCP specific settings
spring.datasource.dbcp2.* Commons DBCP2 specific settings
spring.datasource.driver-class-name Fully qualified JDBC driver name. if not set detect from URL by default.
spring.datasource.generate-unique-name false Generate a random datasource name.
spring.datasource.hikari.* Hikari specific settings
spring.datasource.initialize true allow to execute query using ‘data.sql’.
spring.datasource.jmx-enabled false Enable JMX support (if underlying pool provided).
spring.datasource.jndi-name JNDI location of the datasource other set fields( Class, url, username & password) are ignored when set.
spring.datasource.name testdb datasource name.
spring.datasource.password database login password.
spring.datasource.platform all Platform to use in the schema resource (schema-${platform}.sql).
spring.datasource.schema Schema (DDL) script resource reference.
spring.datasource.schema-username database user to execute DDL scripts (if different).
spring.datasource.schema-password database password to execute DDL scripts (if different).
spring.datasource.separator ; Statement separator in SQL initialization scripts.
spring.datasource.sql-script-encoding SQL scripts encoding.
spring.datasource.tomcat.* Tomcat datasource specific settings
spring.datasource.type connection pool fully qualified name implementation to use. if not set by default detected from the classpath.
spring.datasource.url JDBC database url.
spring.datasource.username database user.
spring.datasource.xa.data-source-class-name fully qualified name of XA data source.
spring.datasource.xa.properties Properties to pass to the XA data source.

JPA Configuration Properties

Spring Boot load these properties in JpaBaseConfiguration and HibernateJpaAutoConfiguration class.

Name Default Value Description
spring.data.jpa.repositories.enabled true Enable JPA repositories.
spring.jpa.database Target database to operate on. It detected by default or alternatively set using the “databasePlatform” property.
spring.jpa.database-platform Name of the target database to operate on. It detected by default or alternatively set using the “Database” enum.
spring.jpa.generate-ddl false Initialize the schema on startup.
spring.jpa.hibernate.ddl-auto DDL mode for the “hibernate.hbm2ddl.auto” property. Default value is “create-drop” when using an embedded database otherwise “none”.
spring.jpa.hibernate.naming.implicit-strategy Hibernate 5 implicit fully qualified naming strategy name .
spring.jpa.hibernate.naming.physical-strategy Hibernate 5 physical fully qualified naming strategy name .
spring.jpa.hibernate.naming.strategy Hibernate 4 fully qualified naming strategy name. Not supported with Hibernate 5.
spring.jpa.hibernate.use-new-id-generator-mappings Use Hibernate’s IdentifierGenerator for AUTO, TABLE and SEQUENCE.
spring.jpa.open-in-view true Register OpenEntityManagerInViewInterceptor. Binds a JPA EntityManager to the thread for request entire processing.
spring.jpa.properties.* Additional native properties set on JPA provider.
spring.jpa.show-sql false Enable SQL statements logging.

JTA Configuration Properties

Spring Boot load these properties in JtaAutoConfiguration class.

Name Default Value Description
spring.jta.enabled true Enable JTA support.
spring.jta.log-dir Transaction logs directory.
spring.jta.transaction-manager-id Transaction manager unique identifier.

Data REST Configuration Properties

Spring Boot load these properties in RepositoryRestProperties class.

Name Default Value Description
spring.data.rest.base-path Base path for Spring Data REST to repository resources.
spring.data.rest.default-page-size Default page size.
spring.data.rest.enable-enum-translation Enable enum value translation through Spring Data REST by default resource bundle.
spring.data.rest.limit-param-name URL query parameter name that decide how many results return at once.
spring.data.rest.max-page-size Maximum size of pages.
spring.data.rest.page-param-name URL query string parameter to indicates what page to return.
spring.data.rest.return-body-on-create Return a response body after creating an entity.
spring.data.rest.return-body-on-update Return a response body after updating an entity.
spring.data.rest.sort-param-name URL query string parameter to indicates what direction to sort results.

H2 Web Console Configuration Properties

Spring Boot load these properties in H2ConsoleProperties class.

Name Default Value Description
spring.h2.console.enabled false Enable the console.
spring.h2.console.path /h2-console Path at which the console will be available.
spring.h2.console.settings.trace false Enable trace output.
spring.h2.console.settings.web-allow-others false Enable remote access.

Data Redis Configuration Properties

Spring Boot load these properties in SecurityProperties class.

Name Default Value Description
spring.data.redis.repositories.enabled true Enable Redis repositories.

Redis Configuration Properties

Spring Boot load these properties in RedisProperties class.

Name Default Value Description
spring.redis.cluster.max-redirects Maximum number of redirects to follow when executing commands across the cluster.
spring.redis.cluster.nodes Comma-separated list of “host:port” pairs to bootstrap from.
spring.redis.database 0 Database index used by the connection factory.
spring.redis.host localhost Redis server host.
spring.redis.password Login password of the redis server.
spring.redis.pool.max-active 8 Max number of connections that can be allocated by the pool at a given time. Use a negative value for no limit.
spring.redis.pool.max-idle 8 Max number of “idle” connections in the pool. Use a negative value to indicate an unlimited number of idle connections.
spring.redis.pool.max-wait -1 Maximum time a connection allocation to block before throwing an exception in case of pool is exhausted. Use -1 to block indefinitely.
spring.redis.pool.min-idle 0 Minimum number of idle connections in pool. This works only when set as positive.
spring.redis.port 6379 Redis server port.
spring.redis.sentinel.master Name of Redis server.
spring.redis.sentinel.nodes Comma-separated host:port pairs.
spring.redis.timeout 0 Connection timeout (milliseconds).

Flyway Configuration Properties

Spring Boot load these properties in FlywayProperties class.

Name Default Value Description
flyway.baseline-description
flyway.baseline-version 1 version to start migration
flyway.baseline-on-migrate
flyway.check-location false Check that migration scripts location exists.
flyway.clean-on-validation-error
flyway.enabled true Enable flyway.
flyway.encoding
flyway.ignore-failed-future-migration
flyway.init-sqls SQL statements to execute immediate to initialize when a connection obtain.
flyway.locations classpath:db/migration locations of migrations scripts
flyway.out-of-order
flyway.password JDBC password In case if you want Flyway create its own DataSource
flyway.placeholder-prefix
flyway.placeholder-replacement
flyway.placeholder-suffix
flyway.placeholders.*
flyway.schemas schemas to update
flyway.sql-migration-prefix V
flyway.sql-migration-separator
flyway.sql-migration-suffix .sql
flyway.table
flyway.url JDBC database url to migrate. Incase not set then use the primary configured data source.
flyway.user Login user of the database to migrate.
flyway.validate-on-migrate

Liquibase Configuration Properties

Spring Boot load these properties in LiquibaseProperties class.

Name Default Value Description
liquibase.change-log classpath:/db/ changelog/db.
changelog-master.yaml
Change log configuration path.
liquibase.check-change-log-location true Check the change log location exists.
liquibase.contexts Comma-separated list of runtime contexts to use.
liquibase.default-schema Default database schema.
liquibase.drop-first false Drop the database schema first.
liquibase.enabled true Enable liquibase support.
liquibase.labels Comma-separated list of runtime labels to use.
liquibase.parameters.* Change log parameters.
liquibase.password Login password of the database to migrate.
liquibase.rollback-file File to rollback SQL statements will be written when an update is performed.
liquibase.url JDBC url of the database to migrate. Incase not set then use the primary configured data source.
liquibase.user Login user of the database to migrate.

Couchbase Configuration Properties

Spring Boot load these properties in CouchbaseProperties class.

Name Default Value Description
spring.couchbase.bootstrap-hosts Couchbase nodes host/IP address to bootstrap from.
spring.couchbase.bucket.name default bucket name connect to.
spring.couchbase.bucket.password bucket password.
spring.couchbase.env.endpoints.key-value 1 Number of sockets per node for each Key/value service.
spring.couchbase.env.endpoints.query 1 Number of sockets per node for each Query (N1QL) service.
spring.couchbase.env.endpoints.view 1 Number of sockets per node for each view service.
spring.couchbase.env.ssl.enabled Enable SSL support. Enabled automatically if a “keyStore” is provided otherwise specified otherwise.
spring.couchbase.env.ssl.key-store Path to JVM key store which holds the certificates.
spring.couchbase.env.ssl.key-store-password Password used to access the key store.
spring.couchbase.env.timeouts.connect 5000 Bucket connections timeout. (in milliseconds)
spring.couchbase.env.timeouts.key-value 2500 Blocking operations performed on a key timeout.( in milliseconds)
spring.couchbase.env.timeouts.query 7500 N1QL query operations timeout.( in milliseconds)
spring.couchbase.env.timeouts.socket-connect 1000 Socket connect connections timeout.( in milliseconds).
spring.couchbase.env.timeouts.view 7500 Regular and geospatial view operations timeout. (in milliseconds).

Cassandra Configuration Properties

Spring Boot load these properties in CassandraProperties class.

Name Default Value Description
spring.data.cassandra.cluster-name Cassandra cluster Name.
spring.data.cassandra.compression Compression supported by the Cassandra binary protocol.
spring.data.cassandra.connect-timeout-millis Socket option: connection time out.
spring.data.cassandra.consistency-level Queries consistency level.
spring.data.cassandra.contact-points localhost Comma-separated cluster node addresses.
spring.data.cassandra.fetch-size Queries default fetch size.
spring.data.cassandra.keyspace-name Keyspace name to use.
spring.data.cassandra.load-balancing-policy Class name of the load balancing policy.
spring.data.cassandra.port Port of the Cassandra server.
spring.data.cassandra.password Login password of the server.
spring.data.cassandra.read-timeout-millis Socket option: read time out.
spring.data.cassandra.reconnection-policy Reconnection policy class.
spring.data.cassandra.repositories.enabled Enable Cassandra repositories.
spring.data.cassandra.retry-policy Class name of the retry policy.
spring.data.cassandra.serial-consistency-level Queries serial consistency level.
spring.data.cassandra.schema-action none Schema action to take at startup.
spring.data.cassandra.ssl false Enable SSL support.
spring.data.cassandra.username Login user of the server.

Data Couchbase Configuration Properties

Spring Boot load these properties in CouchbaseDataProperties class.

Name Default Value Description
spring.data.couchbase.auto-index false create views and indexes automatically.
spring.data.couchbase.consistency read-your-own-writes By default Consistency to apply on generated queries.
spring.data.couchbase.repositories.enabled true Enable Couchbase repositories.

SOLR Configuration Properties

Spring Boot load these properties in SolrProperties class.

Name Default Value Description
spring.data.solr.host http://127.0.0.1:8983/solr Solr host. Ignored if “zk-host” is set.
spring.data.solr.repositories.enabled true Enable Solr repositories.
spring.data.solr.zk-host ZooKeeper host address i.e HOST:PORT.

ElasticSearch Configuration Properties

Spring Boot load these properties in ElasticsearchProperties class.

Name Default Value Description
spring.data.elasticsearch.cluster-name elasticsearch cluster name.
spring.data.elasticsearch.cluster-nodes Comma-separated cluster node addresses. If not specified, starts a client node.
spring.data.elasticsearch.properties.* Additional properties used to configure the client.
spring.data.elasticsearch.repositories.enabled true Enable Elasticsearch repositories.

JEST (Elasticsearch HTTP client) Configuration Properties

Spring Boot load these properties in JestProperties class.

Name Default Value Description
spring.elasticsearch.jest.connection-timeout 3000 Connection timeout in milliseconds.
spring.elasticsearch.jest.password Login password.
spring.elasticsearch.jest.proxy.host Proxy host the HTTP client to use.
spring.elasticsearch.jest.proxy.port Proxy port the HTTP client to use.
spring.elasticsearch.jest.read-timeout 3000 Read timeout. (in milliseconds)
spring.elasticsearch.jest.uris http://localhost:9200 Comma-separated Elasticsearch instances to use.
spring.elasticsearch.jest.username Login user.

Embedded MongoDB Configuration Properties

Spring Boot load these properties in EmbeddedMongoProperties class.

Name Default Value Description
spring.mongodb.embedded.features SYNC_DELAY Comma-separated features to enable.
spring.mongodb.embedded.storage.database-dir Directory used for data storage.
spring.mongodb.embedded.storage.oplog-size Maximum size of the oplog in megabytes.
spring.mongodb.embedded.storage.repl-set-name Name of the replica set.
spring.mongodb.embedded.version 2.6.10 Version of Mongo to use.

MongoDB Configuration Properties

Spring Boot load these properties in MongoProperties class.

Name Default Value Description
spring.data.mongodb.authentication-database Authentication database name.
spring.data.mongodb.database test Database name.
spring.data.mongodb.field-naming-strategy USe Fully qualified name of the FieldNamingStrategy.
spring.data.mongodb.grid-fs-database GridFS database name.
spring.data.mongodb.host localhost Mongo server host.
spring.data.mongodb.password Login password of the mongo server.
spring.data.mongodb.port 27017 Mongo server port.
spring.data.mongodb.repositories.enabled true Enable Mongo repositories.
spring.data.mongodb.uri mongodb://localhost/test Mongo database URI.host and port are ignored when setting it.
spring.data.mongodb.username Login user of the mongo server.

Neo4j Configuration Properties

Spring Boot load these properties in Neo4jProperties class.

Name Default Value Description
spring.data.neo4j.compiler Compiler to use.
spring.data.neo4j.embedded.enabled true Enable embedded mode when embedded driver is available.
spring.data.neo4j.password Login password of the server.
spring.data.neo4j.repositories.enabled true Enable Neo4j repositories.
spring.data.neo4j.session.scope singleton Scope (lifetime) of the session.
spring.data.neo4j.uri URI used by the driver detected by default.
spring.data.neo4j.username Login user of the server.

JOOQ Configuration Properties

Spring Boot load these properties in JooqAutoConfiguration class.

Name Default Value Description
spring.jooq.sql-dialect Use SQLDialect JOOQ when communicating with the configured datasource. For example: `POSTGRES`

Atomikos Configuration Properties

Spring Boot load these properties in AtomikosProperties class.

Name Default Value Description
spring.jta.atomikos.connectionfactory.borrow-connection-timeout 30 Timeout for borrowing connections from the pool. (in seconds)
spring.jta.atomikos.connectionfactory.ignore-session-transacted-flag true Set to ignore the transacted flag when creating session.
spring.jta.atomikos.connectionfactory.local-transaction-mode false Set local transactions are desired.
spring.jta.atomikos.connectionfactory.maintenance-interval 60 The time between runs of the pool’s maintenance thread. (in seconds).
spring.jta.atomikos.connectionfactory.max-idle-time 60 The time after which connections are cleaned up from the pool. (in seconds)
spring.jta.atomikos.connectionfactory.max-lifetime 0 The time that a connection can be pooled for before being destroyed. 0 denotes no limit.(in seconds)
spring.jta.atomikos.connectionfactory.max-pool-size 1 The maximum pool size.
spring.jta.atomikos.connectionfactory.min-pool-size 1 The minimum pool size.
spring.jta.atomikos.connectionfactory.reap-timeout 0 The reap timeout for borrowed connections. 0 denotes no limit.( in seconds)
spring.jta.atomikos.connectionfactory.unique-resource-name jmsConnectionFactory The unique name used to identify the resource during recovery.
spring.jta.atomikos.datasource.borrow-connection-timeout 30 Timeout for borrowing connections from the pool. (in seconds)
spring.jta.atomikos.datasource.default-isolation-level Default isolation level of connections provided by the pool.
spring.jta.atomikos.datasource.login-timeout Timeout for establishing a database connection.(in seconds)
spring.jta.atomikos.datasource.maintenance-interval 60 The time between runs of the pool’s maintenance thread.(in seconds)
spring.jta.atomikos.datasource.max-idle-time 60 The time after which connections are cleaned up from the pool.(in seconds)
spring.jta.atomikos.datasource.max-lifetime 0 The time that a connection can be pooled for before being destroyed. 0 denotes no limit.(in seconds)
spring.jta.atomikos.datasource.max-pool-size 1 The maximum pool size.
spring.jta.atomikos.datasource.min-pool-size 1 The minimum pool size.
spring.jta.atomikos.datasource.reap-timeout 0 The reap timeout for borrowed connections. 0 denotes no limit.(in seconds)
spring.jta.atomikos.datasource.test-query SQL query or statement used to validate a connection before returning it.
spring.jta.atomikos.datasource.unique-resource-name dataSource The unique name used to identify the resource during recovery.
spring.jta.atomikos.properties.checkpoint-interval 500 Interval between checkpoints.
spring.jta.atomikos.properties.default-jta-timeout 10000 Default timeout for JTA transactions.
spring.jta.atomikos.properties.enable-logging true Enable disk logging.
spring.jta.atomikos.properties.force-shutdown-on-vm-exit false Specify if a VM shutdown should trigger forced shutdown of the transaction core.
spring.jta.atomikos.properties.log-base-dir Directory in which the log files should be stored.
spring.jta.atomikos.properties.log-base-name tmlog Transactions log file base name.
spring.jta.atomikos.properties.max-actives 50 Maximum active transactions.
spring.jta.atomikos.properties.max-timeout 300000 Maximum timeout that can be allowed for transactions. (in milliseconds)
spring.jta.atomikos.properties.serial-jta-transactions true Specify if sub-transactions should be joined when possible.
spring.jta.atomikos.properties.service Transaction manager implementation that should be started.
spring.jta.atomikos.properties.threaded-two-phase-commit true Use different (and concurrent) threads for two-phase commit on the resources.
spring.jta.atomikos.properties.transaction-manager-unique-name Transaction manager’s unique name.

Bironix Configuration Properties

 

Name Default Value Description
spring.jta.bitronix.connectionfactory.acquire-increment 1 Number of connections to create when pool grow.
spring.jta.bitronix.connectionfactory.acquisition-interval 1 Time to wait before trying to acquire a connection again after an invalid connection was acquired.(in second)
spring.jta.bitronix.connectionfactory.acquisition-timeout 30 Timeout for acquiring connections from the pool. (in second)
spring.jta.bitronix.connectionfactory.allow-local-transactions true Set the transaction manager should allow mixing XA and non-XA transactions.
spring.jta.bitronix.connectionfactory.apply-transaction-timeout false Set the transaction timeout should be set on the XAResource when it is enlisted.
spring.jta.bitronix.connectionfactory.automatic-enlisting-enabled true Set resources should be enlisted and delisted automatically
spring.jta.bitronix.connectionfactory.cache-producers-consumers true Set produces and consumers should be cached.
spring.jta.bitronix.connectionfactory.defer-connection-release true Set the provider can run many transactions on the same connection and supports transaction interleaving.
spring.jta.bitronix.connectionfactory.ignore-recovery-failures false Set recovery failures should be ignored.
spring.jta.bitronix.connectionfactory.max-idle-time 60 The time after which connections are cleaned up from the pool.(in second)
spring.jta.bitronix.connectionfactory.max-pool-size 10 The maximum pool size. 0 denotes no limit.
spring.jta.bitronix.connectionfactory.min-pool-size 0 The minimum pool size.
spring.jta.bitronix.connectionfactory.password The password to use to connect to the JMS provider.
spring.jta.bitronix.connectionfactory.share-transaction-connections false Set connections in the ACCESSIBLE state can be shared within the context of a transaction.
spring.jta.bitronix.connectionfactory.test-connections true Set connections should be tested when acquired from the pool.
spring.jta.bitronix.connectionfactory.two-pc-ordering-position 1 The position that this resource should take during two-phase commit (always first is Integer.MIN_VALUE, always last is Integer.MAX_VALUE).
spring.jta.bitronix.connectionfactory.unique-name jmsConnectionFactory The unique name used to identify the resource during recovery.
spring.jta.bitronix.connectionfactory.use-tm-join true Set TMJOIN should be used when starting XAResources.
spring.jta.bitronix.connectionfactory.user The user to use to connect to the JMS provider.
spring.jta.bitronix.datasource.acquire-increment 1 Number of connections to create when growing the pool.
spring.jta.bitronix.datasource.acquisition-interval 1 Time to wait before trying to acquire a connection again after an invalid connection was acquired.(in second)
spring.jta.bitronix.datasource.acquisition-timeout 30 Timeout for acquiring connections from the pool. (in second)
spring.jta.bitronix.datasource.allow-local-transactions true Set the transaction manager should allow mixing XA and non-XA transactions.
spring.jta.bitronix.datasource.apply-transaction-timeout false Set the transaction timeout should be set on the XAResource when it is enlisted.
spring.jta.bitronix.datasource.automatic-enlisting-enabled true Set resources should be enlisted and delisted automatically.
spring.jta.bitronix.datasource.cursor-holdability The default cursor holdability for connections.
spring.jta.bitronix.datasource.defer-connection-release true Set the database can run many transactions on the same connection and supports transaction interleaving.
spring.jta.bitronix.datasource.enable-jdbc4-connection-test Set Connection.isValid() is called when acquiring a connection from the pool.
spring.jta.bitronix.datasource.ignore-recovery-failures false Set recovery failures should be ignored.
spring.jta.bitronix.datasource.isolation-level The default isolation level for connections.
spring.jta.bitronix.datasource.local-auto-commit The default auto-commit mode for local transactions.
spring.jta.bitronix.datasource.login-timeout Timeout for establishing a database connection.(in second)
spring.jta.bitronix.datasource.max-idle-time 60 The time after which connections are cleaned up from the pool.(in second)
spring.jta.bitronix.datasource.max-pool-size 10 The maximum pool size. 0 denotes no limit.
spring.jta.bitronix.datasource.min-pool-size 0 The minimum pool size.
spring.jta.bitronix.datasource.prepared-statement-cache-size 0 The target size of the prepared statement cache. 0 disables the cache.
spring.jta.bitronix.datasource.share-transaction-connections false Set connections in the ACCESSIBLE state can be shared within the context of a transaction.
spring.jta.bitronix.datasource.test-query SQL query or statement used to validate a connection before returning it.
spring.jta.bitronix.datasource.two-pc-ordering-position 1 The position that this resource should take during two-phase commit (always first is Integer.MIN_VALUE, always last is Integer.MAX_VALUE).
spring.jta.bitronix.datasource.unique-name dataSource The unique name used to identify the resource during recovery.
spring.jta.bitronix.datasource.use-tm-join true Set TMJOIN should be used when starting XAResources.
spring.jta.bitronix.properties.allow-multiple-lrc false Allow multiple LRC resources to be enlisted into the same transaction.
spring.jta.bitronix.properties.asynchronous2-pc false Enable asynchronously execution of two phase commit. spring.jta.bitronix.properties.background-recovery-interval-seconds 60 Interval at which to run the recovery process in the background.(in seconds) spring.jta.bitronix.properties.current-node-only-recovery true Recover only the current node. spring.jta.bitronix.properties.debug-zero-resource-transaction false Log the creation and commit call stacks of transactions executed without a single enlisted resource. spring.jta.bitronix.properties.default-transaction-timeout 60 Default transaction timeout.(in second) spring.jta.bitronix.properties.disable-jmx false Enable JMX support. spring.jta.bitronix.properties.exception-analyzer Set the fully qualified name of the exception analyzer implementation to use. spring.jta.bitronix.properties.filter-log-status false Enable filtering of logs so that only mandatory logs are written. spring.jta.bitronix.properties.force-batching-enabled true Set if disk forces are batched. spring.jta.bitronix.properties.forced-write-enabled true Set if logs are forced to disk. spring.jta.bitronix.properties.graceful-shutdown-interval 60 Maximum amount of seconds the TM will wait for transactions to get done before aborting them at shutdown time. spring.jta.bitronix.properties.jndi-transaction-synchronization-registry-name JNDI name of the TransactionSynchronizationRegistry. spring.jta.bitronix.properties.jndi-user-transaction-name JNDI name of the UserTransaction. spring.jta.bitronix.properties.journal disk Name of the journal. Can be ‘disk’, ‘null’ or a class name. spring.jta.bitronix.properties.log-part1-filename btm1.tlog Name of the first fragment of the journal. spring.jta.bitronix.properties.log-part2-filename btm2.tlog Name of the second fragment of the journal. spring.jta.bitronix.properties.max-log-size-in-mb 2 Maximum size in megabytes of the journal fragments. spring.jta.bitronix.properties.resource-configuration-filename ResourceLoader configuration file name. spring.jta.bitronix.properties.server-id ASCII ID that must uniquely identify this TM instance. Default to the machine’s IP address. spring.jta.bitronix.properties.skip-corrupted-logs false Skip corrupted transactions log entries. spring.jta.bitronix.properties.warn-about-zero-resource-transaction true Log a warning for transactions executed without a single enlisted resource.

 

Narayana Configuration Properties

Spring Boot load these properties in NarayanaProperties class.

Name Default Value Description
spring.jta.narayana.default-timeout 60 Transaction timeout.(in second)
spring.jta.narayana.expiry-scanners com.arjuna.ats.internal. arjuna.recovery. ExpiredTransactionStatusManagerScanner Comma-separated list of expiry scanners.
spring.jta.narayana.log-dir Transaction object store directory.
spring.jta.narayana.one-phase-commit true Enable one phase commit optimisation.
spring.jta.narayana.periodic-recovery-period 120 Interval in which periodic recovery scans are performed.(in second)
spring.jta.narayana.recovery-backoff-period 10 Back off period between first and second phases of the recovery scan.(in second)
spring.jta.narayana.recovery-db-pass Database password for recovery manager.
spring.jta.narayana.recovery-db-user Database username for recovery manager.
spring.jta.narayana.recovery-jms-pass JMS password for recovery manager.
spring.jta.narayana.recovery-jms-user JMS username for recovery manager.
spring.jta.narayana.recovery-modules Comma-separated recovery modules.
spring.jta.narayana.transaction-manager-id 1 Unique transaction manager id.
spring.jta.narayana.xa-resource-orphan-filters Comma-separated orphan filters.

References

https://docs.spring.io/spring-boot/docs/1.4.x/reference/html/common-application-properties.html

Spring Boot: Security, OAUTH2 and SSO Configuration Properties and Default Value


These are Spring Boot Security Configuration Properties that can be configured with any Spring Boot Web Application. These properties are already configured in Spring Boot with the given default value.

Note: In your application, You don’t need to add all these values in your application.proprties/application.yaml file. You just need to add only those values which you want to change/override.

See Also:

Security Configuration Properties

Spring Boot load these properties in SecurityProperties class.

Name Default Value Description
security.basic.authorize-mode role Security authorize mode to apply.
security.basic.enabled true Enable basic authentication.
security.basic.path /** Comma-separated paths to secure.
security.basic.realm Spring HTTP basic realm name.
security.enable-csrf false Enable Cross Site Request Forgery support.
security.filter-order 0 Security filter chain order.
security.filter-dispatcher-types ASYNC, FORWARD, INCLUDE, REQUEST Security filter chain dispatcher types.
security.headers.cache true Enable cache control HTTP headers.
security.headers.content-type true Enable “X-Content-Type-Options” header.
security.headers.frame true Enable “X-Frame-Options” header.
security.headers.hsts Set HSTS (HTTP Strict Transport Security) as (none, domain, all).
security.headers.xss true Enable cross site scripting (XSS) protection.
security.ignored Comma-separated paths to exclude from the default secured paths.
security.require-ssl false Enable secure channel for all requests.
security.sessions stateless Session creation policy (always, never, if_required, stateless).
security.user.name user Default user name.
security.user.password Password for the default user name. A random password for default logged on.
security.user.role USER Granted roles for the default user name.

Security OAUTH2 Configuration Properties

Spring Boot load these properties in OAuth2ClientProperties class.

Name Default Value Description
security.oauth2.client.client-id OAuth2 client id.
security.oauth2.client.client-secret OAuth2 client secret. A random secret is generated by default

Security OAUTH2 SSO Properties

Spring Boot load these properties in OAuth2SsoProperties class.

Name Default Value Description
security.oauth2.sso.filter-order Filter order if not providing an explicit WebSecurityConfigurerAdapter
security.oauth2.sso.login-path /login Path to the login page,that will redirect to the OAuth2 Authorization

Security OAUTH2 Resources Properties

Spring Boot load these properties in ResourceServerProperties class.

Name Default Value Description
security.oauth2.resource.id Identifier of the resource.
security.oauth2.resource.jwt.key-uri The URI of the JWT token. It can set when value is not available and the key is public.
security.oauth2.resource.jwt.key-value The verification key of the JWT token. Can either be a symmetric secret or PEM-encoded RSA public key.
security.oauth2.resource.prefer-token-info true Use the token info, it can be set to false when the user info.
security.oauth2.resource.service-id resource
security.oauth2.resource.token-info-uri URI of the token decoding endpoint.
security.oauth2.resource.token-type Send token type when using the userInfoUri.
security.oauth2.resource.user-info-uri URI of the user endpoint.

 

References

https://docs.spring.io/spring-boot/docs/1.4.x/reference/html/common-application-properties.html

Spring Boot: Integration Platform Properties and Default Value


These are Spring Boot Integration properties that can be configured with any Spring Boot Application. These properties are already configured in Spring Boot with the given default value.

Note: In your application, You don’t need to add all these values in your application.proprties/application.yaml file. You just need to add only those values which you want to change/override.

See Also:

ActiveMQ Configuration Properties

Spring Boot load these properties in ActiveMQProperties class.

Name Default Value Description
spring.activemq.broker-url URL of the ActiveMQ broker.For Default instance `tcp://localhost:61616`
spring.activemq.in-memory true Required if the default broker URL should be in memory. Ignored if an explicit brokerspecified.
spring.activemq.password Login password of the broker.
spring.activemq.user Login user of the broker.
spring.activemq.packages.trust-all false Trust all packages.
spring.activemq.packages.trusted Comma-separated packages to trust use when not trusting all packages.
spring.activemq.pool.configuration.* See PooledConnectionFactory.
spring.activemq.pool.enabled false Set when PooledConnectionFactory need to create instead of a regular ConnectionFactory.
spring.activemq.pool.expiry-timeout 0 Connection expiration timeout.(millieconds)
spring.activemq.pool.idle-timeout 30000 Connection idle timeout. (millieconds)
spring.activemq.pool.max-connections 1 Maximum number of pooled connections.

ARTEMIS Configuration Properties

Spring Boot load these properties in ArtemisProperties class.

Name Default Value Description
spring.artemis.embedded.cluster-password Cluster password. Randomly generated on startup by default.
spring.artemis.embedded.data-directory Journal file directory. Not necessary if persistence is turned off.
spring.artemis.embedded.enabled true Enable embedded mode, In case Artemis server APIs are available.
spring.artemis.embedded.persistent false Enable persistent store.
spring.artemis.embedded.queues Comma-separated queues to create on startup.
spring.artemis.embedded.server-id Server id. By default, an auto-incremented counter is used.
spring.artemis.embedded.topics Comma-separated topics to create on startup.
spring.artemis.host localhost Artemis broker host.
spring.artemis.mode Artemis deployment mode, auto-detected by default.
spring.artemis.password Login password of the broker.
spring.artemis.port 61616 Artemis broker port.
spring.artemis.user Login user of the broker.

Spring Batch Configuration Properties

Spring Boot load these properties in BatchProperties class.

Name Default Value Description
spring.batch.initializer.enabled Create the required batch tables on startup if needed. Enabled automatically, if custom schema is configured or no custom table prefix is set.
spring.batch.job.enabled true Execute all Spring Batch jobs on context startup.
spring.batch.job.names Comma-separated job names to execute on startup. By default, all Jobs in the context are executed.
spring.batch.schema classpath:org/
springframework/batch
/core/schema
-@@platform@@.sql
SQL file path to use to initialize the database schema.
spring.batch.table-prefix Table prefix for all batch meta-data tables.

HornetQ Configuration Properties

Spring Boot load these properties in HornetQProperties class.

Name Default Value Description
spring.hornetq.embedded.cluster-password Cluster password. Randomly generated on startup by default.
spring.hornetq.embedded.data-directory Journal file directory. Not necessary if persistence is turned off.
spring.hornetq.embedded.enabled true Enable embedded mode In case HornetQ server APIs are available.
spring.hornetq.embedded.persistent false Enable persistent store.
spring.hornetq.embedded.queues Comma-separated queues to create on startup.
spring.hornetq.embedded.server-id Server id. By default, an auto-incremented counter is used.
spring.hornetq.embedded.topics Comma-separated topics to create on startup.
spring.hornetq.host localhost HornetQ broker host.
spring.hornetq.mode HornetQ deployment mode, auto-detected by default.
spring.hornetq.password Login password of the broker.
spring.hornetq.port 5445 HornetQ broker port.
spring.hornetq.user Login user of the broker.

JMS Configuration Properties

Spring Boot load these properties in JmsProperties class.

Name Default Value Description
spring.jms.jndi-name Connection factory JNDI name. When configured, take precedence from others connection factory auto-configurations.
spring.jms.listener.acknowledge-mode Acknowledge mode for conainer. By default, the listener transcted to automatic acknowledgment.
spring.jms.listener.auto-startup true Start the container automatically on startup.
spring.jms.listener.concurrency Minimum number of concurrent consumers.
spring.jms.listener.max-concurrency Maximum number of concurrent consumers.
spring.jms.pub-sub-domain false Specify if the default destination type is topic.

Rabbit Configuration Properties

Spring Boot load these properties in RabbitProperties class.

Name Default Value Description
spring.rabbitmq.addresses Comma-separated addresses to which the client should connect.
spring.rabbitmq.cache.channel.checkout-timeout Waiting time to obtain a channel In case cache size has been reached.(in Millisecond)
spring.rabbitmq.cache.channel.size Number of channels to retain in the cache.
spring.rabbitmq.cache.connection.mode CHANNEL Connection factory cache mode.
spring.rabbitmq.cache.connection.size Number of connections to cache.
spring.rabbitmq.connection-timeout Connection timeout, in milliseconds; zero for infinite.
spring.rabbitmq.dynamic true Create an AmqpAdmin bean.
spring.rabbitmq.host localhost RabbitMQ host.
spring.rabbitmq.listener.acknowledge-mode Acknowledge mode of container
spring.rabbitmq.listener.auto-startup true Start the container automatically on startup.
spring.rabbitmq.listener.concurrency Minimum number of consumers.
spring.rabbitmq.listener.default-requeue-rejected Default true. Set to requeue delivery failures.
spring.rabbitmq.listener.max-concurrency Maximum number of consumers.
spring.rabbitmq.listener.prefetch Number of messages handled in a single request. For good performance, It should be greater than or equal to the transaction size (if configured).
spring.rabbitmq.listener.retry.enabled false Whether or not publishing retries are enabled.
spring.rabbitmq.listener.retry.initial-interval 1000 Interval between the two subsquent attempt to deliver a message.
spring.rabbitmq.listener.retry.max-attempts 3 Maximum attempts to deliver a message.
spring.rabbitmq.listener.retry.max-interval 10000 Maximum interval between attempts.
spring.rabbitmq.listener.retry.multiplier 1.0 Muliplier apply on previous delivery retry interval.
spring.rabbitmq.listener.retry.stateless true Whether or not retry is stateless or stateful.
spring.rabbitmq.listener.transaction-size Number of messages processed in each transaction. For good performnace, it should be less than or equal to the prefetch count.
spring.rabbitmq.password Login to authenticate against the broker.
spring.rabbitmq.port 5672 RabbitMQ port.
spring.rabbitmq.publisher-confirms false Enable publisher confirms.
spring.rabbitmq.publisher-returns false Enable publisher returns.
spring.rabbitmq.requested-heartbeat Requested heartbeat timeout, in seconds; zero for none.
spring.rabbitmq.ssl.enabled false Enable SSL support.
spring.rabbitmq.ssl.key-store key store path that holds the SSL certificate.
spring.rabbitmq.ssl.key-store-password Password used to access the key store.
spring.rabbitmq.ssl.trust-store Trust store that holds SSL certificates.
spring.rabbitmq.ssl.trust-store-password Password used to access the trust store.
spring.rabbitmq.ssl.algorithm SSL algorithm to use. By default configure by the rabbit client library.
spring.rabbitmq.template.mandatory false Enable mandatory messages.
spring.rabbitmq.template.receive-timeout 0 Timeout for `receive()` methods.
spring.rabbitmq.template.reply-timeout 5000 Timeout for `sendAndReceive()` methods.
spring.rabbitmq.template.retry.enabled false Set to true, for enable retries in the `RabbitTemplate`.
spring.rabbitmq.template.retry.initial-interval 1000 Interval between two subsquent attempt to publish a message.
spring.rabbitmq.template.retry.max-attempts 3 Maximum attempts to publish a message.
spring.rabbitmq.template.retry.max-interval 10000 Maximum attempts to publish a message.
spring.rabbitmq.template.retry.multiplier 1.0 Multiplier apply on previous publishing retry interval.
spring.rabbitmq.username Login user to authenticate broker.
spring.rabbitmq.virtual-host Virtual host to while connecting to the broker.

References

https://docs.spring.io/spring-boot/docs/1.4.x/reference/html/common-application-properties.html

Spring Boot: DevTools Properties and Default Value


These are Spring Boot Dev Tools properties that can be configured with any Spring Boot Application. These properties are already configured in Spring Boot with the given default value.

Note: In your application, You don’t need to add all these values in your application.proprties/application.yaml file. You just need to add only those values which you want to change/override.

See Also:

DevTools Configuration Properties

Spring Boot load these properties in DevToolsProperties class.

Name Default Value Description
spring.devtools.livereload.enabled true Enable a livereload.com compatible server.
spring.devtools.livereload.port 35729 Server port.
spring.devtools.restart.additional-exclude Additional patterns excluded from triggering a full restart.
spring.devtools.restart.additional-paths Additional paths to watch for changes.
spring.devtools.restart.enabled true Enable automatic restart.
spring.devtools.restart.exclude META-INF/maven/**,
META-INF/resources/**,
resources/**,static/**,
public/**,templates/**,
**/*Test.class,
**/*Tests.class,
git.properties
File System Patterns that excluded from triggering a full restart.
spring.devtools.restart.poll-interval 1000 Amount of waiting time between polling for classpath changes.(in milliseconds)
spring.devtools.restart.quiet-period 400 Amount of quiet time required before a restart is triggered without classpath changes . (in milliseconds)
spring.devtools.restart.trigger-file Name of file, if any class path file change will trigger the restart. If not specified file n classpath change will trigger the restart.

Remote DevTools Configuration Properties

Spring Boot load these properties in RemoteDevToolsProperties class.

Name Default Value Description
spring.devtools.remote.context-path /.~~spring-boot!~ Context path used to handle the remote connection.
spring.devtools.remote.debug.enabled true Enable remote debug support.
spring.devtools.remote.debug.local-port 8000 Local remote debug server port.
spring.devtools.remote.proxy.host Proxy host to remote application connection
spring.devtools.remote.proxy.port Proxy port to remote application connection.
spring.devtools.remote.restart.enabled true Enable remote restart.
spring.devtools.remote.secret It’s required property,to shared secret to establish a connection
spring.devtools.remote.secret-header-name X-AUTH-TOKEN HTTP header used to transfer the shared secret.

 

References

https://docs.spring.io/spring-boot/docs/1.4.x/reference/html/common-application-properties.html

Spring Boot: Web Application Properties and Default Values


These are Web application common properties that can be configured with any Spring Boot Web Application. These properties are already configured in Spring Boot with the given default value.

Note: In your application, You don’t need to add all these values in your application.proprties/application.yaml file. You just need to add only those values which you want to change/override.

See Also:

Embedded Server Configuration Properties

Spring Boot load these properties in ServerProperties

Name Default Value Description
server.address Network address for the server.
server.compression.enabled false To enable response compression.
server.compression.excluded-user-agents user-agents list to exclude from compression.
server.compression.mime-types Comma-separated MIME typesist that should be compressed. For instance `text/html,text/css,application/json`
server.compression.min-response-size Minimum response size for compression. For instance 2048
server.connection-timeout Connectors wait time (in MilliSeconds) for another HTTP request before closing the connection. If not set then take default as container-specific. If set as -1 for infinite time out.
server.context-parameters.* Servlet context init parameters. For example `server.context-parameters.a=alpha`
server.context-path Application Context path.
server.display-name application Display application name.
server.max-http-header-size 0 Maximum size in bytes for HTTP msg header.
server.max-http-post-size 0 Maximum size in bytes for HTTP post content.
server.error.include-stacktrace never When to include a “stacktrace” attribute.
server.error.path /error Path of navigate in case of the error.
server.error.whitelabel.enabled true Enable the default error page displayed in case of a server error.
server.jetty.acceptors Number of acceptor threads to use.
server.jetty.selectors Number of selector threads to use.
server.jsp-servlet.class-name org.apache.jasper.servlet.JspServlet The class name of the JSP servlet.
server.jsp-servlet.init-parameters.* Init parameters used to configure the JSP servlet.
server.jsp-servlet.registered true Whether or not the JSP servlet is registered.
server.port 8080 HTTP Server port.
server.server-header Server response header value (no header is sent if empty)
server.servlet-path / Path of the main dispatcher servlet.
server.use-forward-headers If X-Forwarded-* headers should be applied in HttpRequest.
server.session.cookie.comment Comment for the session cookie.
server.session.cookie.domain Domain for the session cookie.
server.session.cookie.http-only “HttpOnly” flag for the session cookie.
server.session.cookie.max-age Maximum age of the session cookie in seconds.
server.session.cookie.name Session cookie name.
server.session.cookie.path Path of the session cookie.
server.session.cookie.secure “Secure” flag for the session cookie.
server.session.persistent false Persist session data between restarts.
server.session.store-dir Directory used to store session data.
server.session.timeout Session timeout in seconds
server.session.tracking-modes Session tracking modes either one or more in “cookie”, “url”, “ssl”.
server.ssl.ciphers Supported SSL ciphers.
server.ssl.client-auth Set client authentication is “want” or “need”. Requires a trust store.
server.ssl.enabled Enable SSL support.
server.ssl.enabled-protocols Enabled SSL protocols.
server.ssl.key-alias Alias for identifies the key in the key store.
server.ssl.key-password Password for access the key in the key store.
server.ssl.key-store Path to the key store that holds the SSL certificate (jks file).
server.ssl.key-store-provider Provider for the key store.
server.ssl.key-store-type Type of the key store.
server.ssl.protocol TLS SSL protocol to use.
server.ssl.trust-store Trust store that holds SSL certificates.
server.ssl.trust-store-password Password used to access the trust store.
server.ssl.trust-store-provider Provider for the trust store.
server.ssl.trust-store-type Type of the trust store.
server.tomcat.accesslog.directory logs Directory in which log files are created. i.e tomcat base dir or absolute.
server.tomcat.accesslog.enabled false Enable access log.
server.tomcat.accesslog.pattern common Format pattern for access logs.
server.tomcat.accesslog.prefix access_log Log file name prefix.
server.tomcat.accesslog.rename-on-rotate false Defer inclusion of the date stamp in the file name as long as rotate time.
server.tomcat.accesslog.request-attributes-enabled false Set request attributes for IP address, ptotocol, port and Hostname.
server.tomcat.accesslog.suffix .log Log file name suffix.
server.tomcat.background-processor-delay 30 Delay between the invocation of backgroundProcess methods.(seconds)
server.tomcat.basedir Tomcat base directory. If not set then temporary directory will be used.
server.tomcat.internal-proxies 10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|\\
192\\.168\\.\\d{1,3}\\.\\d{1,3}|\\
169\\.254\\.\\d{1,3}\\.\\d{1,3}|\\
127\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|\\
172\\.1[6-9]{1}\\.\\d{1,3}\\.\\d{1,3}|\\
172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|\\
172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3}
regular expression matching trusted IP addresses.
server.tomcat.max-threads 0 Maximum amount of worker threads.
server.tomcat.min-spare-threads 0 Minimum amount of worker threads.
server.tomcat.port-header X-Forwarded-Port HTTP header name used to override the original port value.
server.tomcat.protocol-header Header value holds the incoming protocol, usually named “X-Forwarded-Proto”.
server.tomcat.protocol-header-https-value https Param Value in header that indicates that the incoming request uses SSL.
server.tomcat.remote-ip-header http header param from which the remote ip is extracted. For instance `X-FORWARDED-FOR`
server.tomcat.uri-encoding UTF-8 Character encoding to use to decode the URI.
server.undertow.accesslog.dir Undertow access log directory.
server.undertow.accesslog.enabled false Enable access log.
server.undertow.accesslog.pattern common Format pattern for access logs.
server.undertow.accesslog.prefix access_log. Log file name prefix.
server.undertow.accesslog.suffix log Log file name suffix.
server.undertow.buffer-size Each buffer size in bytes.
server.undertow.buffers-per-region Number of buffer for per region.
server.undertow.direct-buffers Allocate buffers space outside the Java heap.
server.undertow.io-threads Number of worker threads create for I/O.
server.undertow.worker-threads Number of worker threads.

Freemarker Properties

Spring Boot load these properties in FreeMarkerAutoConfiguration

Name Default Value Description
spring.freemarker.allow-request-override false HttpServletRequest attributes of same name are allowed to override controller generated model attributes.
spring.freemarker.allow-session-override false Enable HttpSession attributes of same name are allowed to override controller generated model attributes.
spring.freemarker.cache false Enable template caching
spring.freemarker.charset UTF-8 Template encoding.
spring.freemarker.check-template-location true Check that the templates location exists.
spring.freemarker.content-type text/html Content-Type value.
spring.freemarker.enabled true Enable MVC view resolution for this technology.
spring.freemarker.expose-request-attributes false Enable all request attributes should be added to the model prior to merging with the template.
spring.freemarker.expose-session-attributes false Enable all HttpSession attributes should be added with model prior to merging with the template.
spring.freemarker.expose-spring-macro-helpers true Enable expose a RequestContext for use by Spring’s macro library, under the name “springMacroRequestContext”.
spring.freemarker.prefer-file-system-access true Enable hot detection of template changes from file system.
spring.freemarker.prefix Prefix prepended with view names when building a URL.
spring.freemarker.request-context-attribute Name of the RequestContext attribute that will apply on all views.
spring.freemarker.settings.* Well-known FreeMarker keys that will passed to FreeMarker’s Configuration.
spring.freemarker.suffix Suffix appended with view names when building a URL.
spring.freemarker.template-loader-path classpath:/templates/ Comma-separated template paths.
spring.freemarker.view-names White list of view names.

Groovy Template Properties

Spring Boot load these properties in GroovyTemplateAutoConfiguration

Name Default Value Description
spring.groovy.template.allow-request-override false HttpServletRequest attributes of same name are allowed to override controller generated model attributes.
spring.groovy.template.allow-session-override false HttpSession attributes of same name are allowed to override (hide) controller generated model attributes..
spring.groovy.template.cache Enable template caching.
spring.groovy.template.charset UTF-8 Template encoding.
spring.groovy.template.check-template-location true Check that the templates location exists.
spring.groovy.template.configuration.* See GroovyMarkupConfigurer
spring.groovy.template.content-type test/html Content-Type value.
spring.groovy.template.enabled true Enable MVC view resolution for this technology.
spring.groovy.template.expose-request-attributes false Enable All request attributes added with model prior to merging with the template.
spring.groovy.template.expose-session-attributes false Enable All HttpSession attributes added with model prior to merging with the template.
spring.groovy.template.expose-spring-macro-helpers true Enable expose a RequestContext for use by Spring’s macro library, under the name “springMacroRequestContext”.
spring.groovy.template.prefix Prefix prepended with view names when building a URL.
spring.groovy.template.request-context-attribute Name of the RequestContext attribute for all views.
spring.groovy.template.resource-loader-path classpath:/templates/ Template path.
spring.groovy.template.suffix .tpl Suffix appended with view names when building a URL.
spring.groovy.template.view-names White list of view names.

Spring HATEOAS Properties

Spring Boot load these properties in HateoasProperties

Name Default Value Description
spring.hateoas.use-hal-as-default-json-media-type true Enable application/hal+json mime type responses for requests that accept application/json.

HTTP Message Conversion Properties

Name Default Value Description
spring.http.converters.preferred-json-mapper jackson Preferred JSON mapper for HTTP message conversion. Specified “gson” in case jacson and gson both are on the classpath.

HTTP Encoding Properties

Spring Boot load these properties in HttpEncodingProperties class.

Name Default Value Description
spring.http.encoding.charset UTF-8 Charset of HTTP requests and responses. Added to the “Content-Type” header.
spring.http.encoding.enabled true Enable http encoding.
spring.http.encoding.force Force the encoding on HTTP requests and responses.
spring.http.encoding.force-request Force the encoding on HTTP requests. Defaults to true.
spring.http.encoding.force-response Force the encoding on HTTP responses.
spring.http.encoding.mapping Locale to Encoding mapping.

Multipart Properties

Spring Boot load these properties in MultipartProperties class.

Name Default Value Description
spring.http.multipart.enabled true Enable support of multi-part uploads.
spring.http.multipart.file-size-threshold 0 Threshold after which files will be written to disk.Suffixed “MB” or “KB”.
spring.http.multipart.location Intermediate location of uploaded files.
spring.http.multipart.max-file-size 1Mb Max file size. Suffixed “MB” or “KB”.
spring.http.multipart.max-request-size 10Mb Max request size. Suffixed “MB” or “KB”.
spring.http.multipart.resolve-lazily false Set to resolve the multipart request lazily when file or parameter access.

Jackson Properties

Spring Boot load these properties in JacksonProperties class.

Name Default Value Description
spring.jackson.date-format Date format or a fully-qualified date format class name. For example `yyyy-MM-dd HH:mm:ss`.
spring.jackson.default-property-inclusion Controls the properties inclusion during serialization.
spring.jackson.deserialization.* on/off features for Jackson that affect the way Java objects are deserialized.
spring.jackson.generator.* on/off features for Jackson generators.
spring.jackson.joda-date-time-format Joda date time strig format. If it is configured with a format string use it otherwise will use “date-format” as a fallback .
spring.jackson.locale Locale used for formatting.
spring.jackson.mapper.* on/off features of Jackson general features.
spring.jackson.parser.* on/off features for Jackson parsers.
spring.jackson.property-naming-strategy Set Jackson’s PropertyNamingStrategy type sub class as a fully-qualified class name.
spring.jackson.serialization.* on/off features of Jackson that affect the way Java objects are serialized.
spring.jackson.serialization-inclusion Controls the properties inclusion during serialization by configuring values in Jackson’s JsonInclude.Include enumeration.
spring.jackson.time-zone Time zone for date. For example `America/Los_Angeles`

Jersey Properties

Spring Boot load these properties in JerseyProperties class.

Name Default Value Description
spring.jersey.application-path base URI path for the application that override the value of “@ApplicationPath” if specified.
spring.jersey.filter.order 0 Jersey filter chain order.
spring.jersey.init.* Init parameters to pass to Jersey through servlet or filter.
spring.jersey.servlet.load-on-startup -1 Load on startup priority of the Jersey servlet.
spring.jersey.type servlet Jersey integration type.

Spring Mobile Device Views Properties

Spring Boot load these properties in DeviceDelegatingViewResolverAutoConfiguration class.

Name Default Value Description
spring.mobile.devicedelegatingviewresolver.enable-fallback false Enable support for fallback resolution.
spring.mobile.devicedelegatingviewresolver.enabled false Enable device view resolver.
spring.mobile.devicedelegatingviewresolver.mobile-prefix mobile/ Prefix prepended to view names of mobile devices.
spring.mobile.devicedelegatingviewresolver.mobile-suffix Suffix appended to view names of mobile devices.
spring.mobile.devicedelegatingviewresolver.normal-prefix Prefix prepended to view names of normal devices.
spring.mobile.devicedelegatingviewresolver.normal-suffix Suffix appended to view names of normal devices.
spring.mobile.devicedelegatingviewresolver.tablet-prefix tablet/ Prefix prepended to view names of tablet devices.
spring.mobile.devicedelegatingviewresolver.tablet-suffix Suffix appended to view names of tablet devices.

Spring Mobile Site Preference Properties

Spring Boot load these properties in SitePreferenceAutoConfiguration class.

Name Default Value Description
spring.mobile.sitepreference.enabled true Enable SitePreferenceHandler.

Mustache Templates Properties

Spring Boot load these properties in MustacheAutoConfiguration class.

Name Default Value Description
spring.mustache.allow-request-override HttpServletRequest attributes with same name are allowed to override controller generated model attributes..
spring.mustache.allow-session-override HttpSession attributes with same name are allowed to override controller generated model attributes.
spring.mustache.cache Enable template caching.
spring.mustache.charset Template encoding.
spring.mustache.check-template-location Check that the templates location exists.
spring.mustache.content-type Content-Type value.
spring.mustache.enabled Enable MVC view resolution for this technology.
spring.mustache.expose-request-attributes All request attributes added to the model prior to merging with the template.
spring.mustache.expose-session-attributes All HttpSession attributes added to the model prior to merging with the template.
spring.mustache.expose-spring-macro-helpers Expose a RequestContext use Spring’s macro library, under the name “springMacroRequestContext”.
spring.mustache.prefix classpath:/templates/ Prefix to template names.
spring.mustache.request-context-attribute RequestContext attribute name for all views.
spring.mustache.suffix .html Suffix to template names.
spring.mustache.view-names White list of view names.

Spring MVC Properties

Spring Boot load these properties in WebMvcProperties class.

Name Default Value Description
spring.mvc.async.request-timeout Amount of time before asynchronous request handling times out.(in milliseconds)
spring.mvc.date-format Date format For example `dd/MM/yyyy`.
spring.mvc.dispatch-trace-request false Dispatch TRACE requests to the FrameworkServlet doService method.
spring.mvc.dispatch-options-request true Dispatch OPTIONS requests to the FrameworkServlet doService method.
spring.mvc.favicon.enabled true Enable resolution of favicon.ico.
spring.mvc.formcontent.putfilter.enabled true Enable Spring’s HttpPutFormContentFilter.
spring.mvc.ignore-default-model-on-redirect true Content of the “default” model need to ignored during redirect scenarios.
spring.mvc.locale Set Locale otherwise By default locale is overridden by the “Accept-Language” header.
spring.mvc.locale-resolver accept-header Define how locale should be resolved.
spring.mvc.log-resolved-exception false Enable warn logging, for exceptions resolved by a “HandlerExceptionResolver”.
spring.mvc.media-types.* Maps file extensions for content negotiation.
spring.mvc.message-codes-resolver-format Formatting strategy for message codes. For example `PREFIX_ERROR_CODE`.
spring.mvc.servlet.load-on-startup -1 Load on startup priority for Spring Web Services servlet.
spring.mvc.static-path-pattern /** Path pattern used for static resources.
spring.mvc.throw-exception-if-no-handler-found false If a “NoHandlerFoundException”, then throw if no Handler was found to process a request.
spring.mvc.view.prefix Prefix for Spring MVC view.
spring.mvc.view.suffix Suffux for Spring MVC view.

Spring Resources Handling Properties

Spring Boot load these properties in ResourceProperties class.

.

Name Default Value Description
spring.resources.add-mappings true Enable default resource handling.
spring.resources.cache-period Cache period (in seconds)for the resources served by the resource handler.
spring.resources.chain.cache true Enable caching in the Resource chain.
spring.resources.chain.enabled Enable the Spring Resource Handling chain. By default disabled as long as one strategy has been enabled.
spring.resources.chain.gzipped false Enable resolution of already gzipped resources.
spring.resources.chain.html-application-cache false Enable HTML5 application cache manifest rewriting.
spring.resources.chain.strategy.content.enabled false Enable the content for Version Strategy.
spring.resources.chain.strategy.content.paths /** Comma-separated list of patterns for Version Strategy.
spring.resources.chain.strategy.fixed.enabled false Enable the fixed Version Strategy.
spring.resources.chain.strategy.fixed.paths /** Comma-separated list of patterns for Version Strategy.
spring.resources.chain.strategy.fixed.version Version string for Version Strategy.
spring.resources.static-locations classpath:/META-INF/resources/, classpath:/resources/,
classpath:/static/,
classpath:/public/
Locations of static resources

Spring Session Properties

Spring Boot load these properties in SessionProperties class.

Name Default Value Description
spring.session.hazelcast.map-name spring:session:sessions Name of the map used to store sessions.
spring.session.jdbc.initializer.enabled If necessary, Create the required session tables on startup if necessary. Enabled automatically if the default a custom schema is configured or table name is set.
spring.session.jdbc.schema classpath:
org/springframework/
session/jdbc/
schema-@@platform
@@.sql
SQL file Path for initialize the database schema.
spring.session.jdbc.table-name SPRING_SESSION Name of database table used to store sessions.
spring.session.mongo.collection-name sessions Collection name used to store sessions.
spring.session.redis.flush-mode Flush mode for the Redis sessions.
spring.session.redis.namespace Namespace for keys used to store sessions.
spring.session.store-type Session store type.

Spring Social Properties

Spring Boot load these properties in SocialWebAutoConfiguration class.

Name Default Value Description
spring.social.auto-connection-views false Enable the connection status for supported providers.

Spring Social Facebook Properties

Spring Boot load these properties in FacebookAutoConfiguration class.

Name Default Value Description
spring.social.facebook.app-id Your Facebook App ID
spring.social.facebook.app-secret Your Facebook App Secret

Spring Social LinkedIn Properties

Spring Boot load these properties in LinkedInAutoConfiguration class.

Name Default Value Description
spring.social.linkedin.app-id Your LinkedIn App ID
spring.social.linkedin.app-secret Your LinkedIn App Secret

Spring Local Twitter Properties

Spring Boot load these properties in TwitterAutoConfiguration class.

Name Default Value Description
spring.social.twitter.app-id Your Twitter App ID
spring.social.twitter.app-secret Your Twitter App Secret

Thymeleaf Properties

Spring Boot load these properties in ThymeleafAutoConfiguration class.

Name Default Value Description
spring.thymeleaf.cache true Enable template caching.
spring.thymeleaf.check-template true Check that the template exists..
spring.thymeleaf.check-template-location true Check that the templates location.
spring.thymeleaf.content-type text/html Content-Type value.
spring.thymeleaf.enabled true Enable MVC Thymeleaf view resolution.
spring.thymeleaf.encoding UTF-8 Template encoding.
spring.thymeleaf.excluded-view-names Comma-separated list of view names that can excluded from resolution.
spring.thymeleaf.mode HTML5 Template mode to be applied to templates. Refer StandardTemplateModeHandlers.
spring.thymeleaf.prefix classpath:/templates/ Prefix prepended to view names for building a URL.
spring.thymeleaf.suffix .html Suffix appended to view names for building a URL.
spring.thymeleaf.template-resolver-order template resolver order in chain.
spring.thymeleaf.view-names Comma-separated list of view names.

Velocity Templates Properties

Spring Boot load these properties in VelocityAutoConfiguration class.

Name Default Value Description
spring.velocity.allow-request-override false HttpServletRequest attributes with same name are allowed to override controller generated model attributes.
spring.velocity.allow-session-override false HttpSession attributes with same name are allowed to override controller generated model attributes.
spring.velocity.cache Enable template caching.
spring.velocity.charset UTF-8 Template encoding.
spring.velocity.check-template-location true Check that the templates location exists.
spring.velocity.content-type text/html Content-Type value.
spring.velocity.date-tool-attribute Name of the DateTool helper object to expose in the Velocity context of the view.
spring.velocity.enabled true Enable MVC view resolution for this technology.
spring.velocity.expose-request-attributes false all request attributes should be added to the model prior to merging with the template.
spring.velocity.expose-session-attributes false all HttpSession attributes should be added to the model prior to merging with the template.
spring.velocity.expose-spring-macro-helpers true expose a RequestContext for use by Spring’s macro library, under the name “springMacroRequestContext”.
spring.velocity.number-tool-attribute Name of the NumberTool helper object to expose in the Velocity context of the view.
spring.velocity.prefer-file-system-access true Prefer file system access for template loading for hot detection of template changes.
spring.velocity.prefix Prefix prepended to view names for building a URL.
spring.velocity.properties.* Additional velocity properties.
spring.velocity.request-context-attribute Name of the RequestContext attribute for all views.
spring.velocity.resource-loader-path classpath:/templates/ Template path.
spring.velocity.suffix .vm Suffix appended to view names for building a URL.
spring.velocity.toolbox-config-location Velocity Toolbox config location. For instance `/WEB-INF/toolbox.xml`
spring.velocity.view-names White list of view names.

Spring Web Service Properties

Spring Boot load these properties in WebServicesProperties class.

Name Default Value Description
spring.webservices.path /services Path that serves as the base URI.
spring.webservices.servlet.init Servlet init parameters Spring for Sevices.
spring.webservices.servlet.load-on-startup -1 Load on startup priority for Spring Web Services servlet.

References

https://docs.spring.io/spring-boot/docs/1.4.x/reference/html/common-application-properties.html

Spring Boot: Core Common Properties and Default Value


These are core properties that can be configured with any Spring Boot Application. These properties are already configured in Spring Boot with the given default value.

Note: In your application, You don’t need to add all these values in your application.proprties/ application.YAML file. You just need to add only those values which you want to change/override.

See Also:

Banner Properties

Name Default Value Description
banner.charset UTF-8 Banner file encoding.
banner.location classpath:banner.txt Banner file location.
banner.image.location classpath:banner.gif Banner image file location, also use jpg/png.
banner.image.width 76 Width of the banner image in chars.
banner.image.height Height of the banner image in chars.
banner.image.margin 2 Left hand image margin in chars.
banner.image.invert false If images need to inverted for dark terminal themes.

Logging Properties

Name Default Value Description
logging.config Location of the logging configuration file. For instance `classpath:logback.xml` for Logback
logging.exception-conversion-word %wEx Conversion word used when logging exceptions.
logging.file Log file name. For instance `myapp.log`
logging.level.* Log levels severity mapping. For instance logging.level.org.springframework=DEBUG
logging.path Location of the log file. For instance ‘/var/log’
logging.pattern.console Appender pattern for output to the console. Only supported with the default logback setup.
logging.pattern.file Appender pattern for output to the file. Only supported with the default logback setup.
logging.pattern.level Appender pattern for log level (default %5p). Only supported with the default logback setup.
logging.register-shutdown-hook false Register a shutdown hook on time of initialization for the logging system.

AOP Properties

Name Default Value Description
spring.aop.auto true Add @EnableAspectJAutoProxy.
spring.aop.proxy-target-class false false when Standard Java interface-based proxies. true when subclass-based (CGLIB) proxies.

Application Identity Properties

Spring Boot load these properties in ContextIdApplicationContextInitializer class.

Name Default Value Description
spring.application.index Application index.
spring.application.name Application name

Admin Properties

Spring Boot load these properties in SpringApplicationAdminJmxAutoConfiguration class.

Name Default Value Description
spring.application.admin.enabled false Enable admin features for the application.
spring.application.admin.jmx-name org.springframework.boot:type=Admin,name=SpringApplication #JMX name of the application admin MBean.

Auto Configuration Properties

Name Default Value Description
spring.autoconfigure.exclude Auto-configuration classes to exclude.

Spring Core Properties

Name Default Value Description
spring.beaninfo.ignore true Skip search of BeanInfo classes.

Spring Cache Properties

Spring Boot load these properties in CacheProperties class.

Name Default Value Description
spring.cache.cache-names If supported by cache manager, then mentioned Comma-separated list.
spring.cache.caffeine.spec The specification to use to create caches. For Example: Check CaffeineSpec for more details on the spec format.
spring.cache.couchbase.expiration 0 By default the entries never expire(You can write in milliseconds).
spring.cache.ehcache.config Configuration file location to initialize EhCache.
spring.cache.guava.spec The specification to use to create caches.For Example: Check CacheBuilderSpec for more details on the spec format.
spring.cache.hazelcast.config Configuration file location to initialize Hazelcast.
spring.cache.infinispan.config Configuration file location to initialize Infinispan.
spring.cache.jcache.config Configuration file location to initialize the cache manager
spring.cache.jcache.provider Fully qualified name of the Cache Provider implementation to use to retrieve the JSR-107 compliant cache manager. It only required if more than one JSR-107 implementation is available on the classpath.
spring.cache.type Cache type, auto-detected according to the environment.

Spring Config Properties

Spring Boot load these properties in ConfigFileApplicationListener class when using environment properties.

Name Default Value Description
spring.config.location Config file locations
spring.config.name application Config file name.

HAZELCAST Properties

Spring Boot load these properties in HazelcastProperties class.

Name Default Value Description
spring.hazelcast.config The location of the configuration file to initialize Hazelcast.

Project Information Properties

Spring Boot load these properties in ProjectInfoProperties class.

Name Default Value Description
spring.info.build.location classpath:META-INF/build-info.properties Location for generated build-info.properties file.
spring.info.git.location classpath:git.properties Location generforated git.properties file.

JMX Properties

Name Default Value Description
spring.jmx.default-domain JMX domain name.
spring.jmx.enabled true Expose management beans for JMX domain.
spring.jmx.server mbeanServer MBeanServer bean name.

Email Properties

Spring Boot load these properties in MailProperties class.

Name Default Value Description
spring.mail.default-encoding UTF-8 Default MimeMessage encoding.
spring.mail.host SMTP server host. For instance ‘smtp.example.com’
spring.mail.jndi-name Session JNDI name. When set, takes precedence to others mail settings.
spring.mail.password Login password of the SMTP server.
spring.mail.port SMTP server port.
spring.mail.properties.* Additional JavaMail session properties
spring.mail.protocol smtp Protocol used by the SMTP server.
spring.mail.test-connection false Mail server is available on startup.
spring.mail.username Login user of the SMTP server.

Application Settings Properties

Spring Boot load these properties in SpringApplication class.

Name Default Value Description
spring.main.banner-mode console Mode for display the banner when the application startup.
spring.main.sources Sources (class name, package name or XML resource location) in the ApplicationContext.
spring.main.web-environment Run the application in a web environment. it auto-detected by default.

File Encoding Properties

Spring Boot load these properties in FileEncodingApplicationListener class.

Name Default Value Description
spring.mandatory-file-encoding Expected character encoding the application must use.

Internationalization Properies

Spring Boot load these properties in MessageSourceAutoConfiguration class.

Name Default Value Description
spring.messages.always-use-message-format false Setting whether to always apply the MessageFormat rules, parsing even messages without arguments.
spring.messages.basename messages Comma-separated list of basenames and each following the ResourceBundle convention.
spring.messages.cache-seconds -1 Loaded resource bundle files cache expiration, in seconds. When set to -1, bundles are cached forever.
spring.messages.encoding UTF-8 Message bundles encoding.
spring.messages.fallback-to-system-locale true Setting to fall back to the system Locale if no files for a specific Locale have been found.

Output Properties

Name Default Value Description
spring.output.ansi.enabled detect Configure the ANSI output.

PID FILE Properties

Spring Boot load these properties in ApplicationPidFileWriter class.

Name Default Value Description
spring.pid.fail-on-write-error Fail if ApplicationPidFileWriter is used but not write the PID file.
spring.pid.file Location to PID file to write. if ApplicationPidFileWriter is used.

Profile Properties

Name Default Value Description
spring.profiles.active A comma-separated list of active profiles.
spring.profiles.include Unconditionally activate the specified comma separated profiles

SENDGRID Properties

Spring Boot load these properties in SendGridAutoConfiguration class.

Name Default Value Description
spring.sendgrid.api-key SendGrid api key (alternative to username/password)
spring.sendgrid.username SendGrid account username
spring.sendgrid.password SendGrid account password
spring.sendgrid.proxy.host SendGrid proxy host
spring.sendgrid.proxy.port SendGrid proxy

References

https://docs.spring.io/spring-boot/docs/1.4.x/reference/html/common-application-properties.html

Gradle Overview


“Gradle is advanced, open-source, a general-purpose build automation system that built over ANT, Ivy and Maven repositories”.

Points to Remember

  • Gradle initial version introduced in 2007.
  • Gradle stable current release 6.3 on March 24, 2020
  • Gradle official website https://gradle.org/
  • Gradle API is designed using Groovy Language specifically for Java projects.
  • Gradle supports groovy based DSL (Domain Specific Language) over XML.
  • Gradle is a solution to resolve the dependency management issue of Maven.

See Also:

Features of Gradle

Gradle provides the following features:

  • Open source: Gradle is a free open source project, licensed under the ASL (Apache Software License).
  • Groovy: Gradle’s build script and API are written in Groovy. Gradle is designed towards being used as a language, not as a rigid framework.
  • Language for dependency-based programming: Gradle provides a declarative language for a general-purpose task graph, which you can be leverage in your build.
  • Gradle API: These APIs allows to monitor, customize configuration and execution behavior to its core functionality
  • Declarative builds: Gradle is Domain Specific Language (DSL) based on Groovy language. It provides a declarative language element that provides build-by-convention support for Java, OSGI, Groovy, Scala OSGI, and Web.
  • Structure your build: Gradle allows implement common design principles which will give a well-structured and easily maintained comprehensible build.
  • Gradle Wrapper: It is useful for the continuous integration of servers and helps to execute Gradle builds on machines where Gradle is not installed.
  • Gradle scales: Gradle is easily capable of making builds for a single project to enterprise application of multiple projects.
  • Multi-Project Builds: Gradle is capable of doing multi-project builds and supports partial builds also. If you build a project Gradle takes care of building all dependent subprojects.
  • Gradle is the first build integration tool: Gradle fully supported for ANT tasks, Maven and lvy repository for publishing and retrieving dependencies. Gradle provides a converter for Maven pom.xml to the Gradle script.
  • Ease of migration: Gradle can easily adapt to any structure Therefore you can always develop your Gradle build script in the same branch where you want to build.

 

Maven Vs Gradle


Gradle is a built tool developed over Maven and Ant. It’s having lots of differences when compared with Maven.

See Also:

Maven Gradle
Maven uses XML Gradle doesn’t use XML
Maven written in Java Gradle written in Java, Kotlin and Gradle
Maven scripts are not shorter and clean Gradle Scripts are shorter and clean
Maven is a software project management and builds tool developed for Java-based applications. Gradle is an open-source, build automation system built on concepts of maven and ant.
Maven makes build process easier, provides best guidelines for development and allow to migrate new features Gradle allows structuring of build and supports for multi projects builds. Gradle increases productivity provides ways to migrate and builds applications.

Maven Vs Ant


Ant was the first “modern” java application build tool released in 2000. It was famous in a short time because easy to learn, based on procedural programming and not required any additional preparation.

Ant was having some issues in terms of, build time, performance and big scripts and other problems of developers.

Maven releases in 2004 which covers all the problems of Ant and having a complete life cycle.

See Also:

Maven vs Ant

Here are some main differences between Maven and Ant build tool.

Ant Maven
Ant required build script per project. Maven describes the project over configuration.
Ant invoke project-specific targets Maven invoke defined goals (target)
Ant is for “just” build process Maven required knowledge of the project.
Ant scripts are too complex. Maven creates standard project layout and builds in the lifecycle.
Ant scripts are not reusable. Maven plugins and repository are reusable.

 

Spring Boot Maven Application


In the previous article, you have learned about Spring Boot System Requirements. In this article, you will learn about steps to create Spring Boot Application in the Maven environment.

  1. Check Java Version
  2. Check Maven Version
  3. Create Application in Maven
  4. Add Spring Boot Parent
  5. Add spring-boot-stater-
  6. Add Business Functionality
  7. Build & Run

Here you will know in detail about each step.

Check Java Version

You can run command java -version to get the current java version installed in your machine.

Java Version

If you are not getting version as above in screen then follow steps in this link: Setup Java/JDK and Eclipse On Window & Linux

Check Maven Version

You can run command mvn -version to get the current Maven version installed in your machine.

Maven Version

If you are not getting version as above in screen then follow steps in this link: Configure Maven in Window and Linux?

Create Application in Maven

To Create a Maven-based Web application, go to the directory where you want to create an application run below maven command.


mvn archetype:generate -DgroupId=com.fiot  -DartifactId=SpringBootMavenApp -DarchetypeArtifactId=maven-archetype-quickstart  -DinteractiveMode=false

Create Maven Application

It will create a java maven application with the below directory structure.


SpringBootMavenApp
-src
--main
---java
----com
-----fiot
------App.java
--test
---java
----com
-----fiot
------AppTest.java
-pom.xml

Add spring-boot-stater

Added highlighted lines of the statement in pom.xml to make your application Spring Boot Web Application.

Spring Boot Maven POM

Let’s discuss in detail these three sections.

spring-boot-starter-parent: It’s a special starter that inherits useful maven defaults. It also provides dependency management so that omit version tags for dependencies.

spring-boot-starter-web: It’s add in the dependencies section to make application as a web which will add all required dependencies for a web application.

Also See: Spring Boot Starters List

spring-boot-maven-plugin: This plugin is used to create an executable jar of your application.

Add Business Functionality

Now your application is having Spring Boot features. You can add your business functionality as per requirement. In this below code we can create one REST service which returns the response as “Hello World!”.

package com.fiot;

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;

@RestController
@EnableAutoConfiguration
public class App
{
	@RequestMapping("/")
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(App.class, args);
    }

}

Here this main method is the starting point of your Spring Boot application that will start Spring container, create beans, load configuration and perform required actions to start the application.

@RestController: This is stereotype annotation which helps to understand the users and Spring framework like whats the purpose of this class like Spring will consider this class when any web request will come.

@RequestMapping: This annotation provides routing information. In this example, tell Spring that any HTTP request with the path “/” should be mapped to the home method.

@EnableAutoConfiguration: This is class-level annotation, which tells to spring boot to guess how you want to configure spring based on configured starters in classpaths and jars. Since in pom.xml we have added spring-boot-starter-web added Tomcat and Spring MVC, the auto-configuration will assume you want to develop a web-based application.

Build & Run

To build your application just go to the root directory of the application and run below command.


mvn package

When you run this command it will take time because download required dependencies from maven repository and after successful compile and package. It will create one more folder as a target in the root of your application.

To run your application use below command.


java -jar ./target/SpringBootMavenApp-1.0-SNAPSHOT.jar

When an application successfully executed then got to the browser and in address bar use this URL http://localhost:8080 after submit you will get a response as “Hello World!!”.

Spring Boot Starters


Spring Boot supports the number of “Starters” that make developer life easy so that more focus on functionality implementation instead of thing about dependencies and it’s version. If any starter is added then it will add all dependent jars in your classpath.

In our previous article, Spring Boot Maven Application has used two Spring Boot starters as given below:

spring-boot-starter-parent

It’s a special starter that inherits useful maven defaults. It also provides dependency management so that omit version tags for dependencies.


 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.21.RELEASE</version>
    </parent>

See Also: spring-boot-starter-parent in Detail.

spring-boot-starter-web

It’s add in the dependencies section to make application as a web which will add all required dependencies for a web application.


<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

To get your application dependency list using command mvn dependency:tree which represents dependencies in the form of a tree. You can use the command as below:


mvn dependency:tree

Spring Boot Starters

Here is a list of Spring Boot Starters which used for adding specific features to your application.

Name Description
spring-boot-starter-parent Use for core starter, logging, YAML support, and auto-configuration.
spring-boot-starter-web Use for building web, RESTful, applications using Spring MVC. By default embedded tomcat container.
spring-boot-starter-aop Use for AOP with Spring AOP and AspectJ.
spring-boot-starter-data-jpa Use for Spring Data JPA with Hibernate.
spring-boot-starter-test Use to test application with libraries including JUnit, Mockito and Hamcrest.
spring-boot-starter-jdbc Use for JDBC with the Tomcat JDBC connection pool.
spring-boot-starter-thymeleaf Use to build MVC web applications using Thymeleaf views.
spring-boot-starter-data-couchbase Use for Couchbase document-oriented database and Spring Data Couchbase.
spring-boot-starter-artemis Use for JMS messaging using Apache Artemis.
spring-boot-starter-web-services Use for Spring Web Services.
spring-boot-starter-mail Use to support Java Mail and Spring Framework’s email sending.
spring-boot-starter-data-redis Use for Redis key-value data store with Spring Data Redis and the Jedis client.
spring-boot-starter-data-gemfire Use to GemFire distributed data store and Spring Data GemFire.
spring-boot-starter-activemq Use to JMS messaging using Apache ActiveMQ.
spring-boot-starter-data-elasticsearch Use to Elasticsearch search and analytics engine and Spring Data Elasticsearch.
spring-boot-starter-integration Use for Spring Integration.
spring-boot-starter-mobile Use for building web applications using Spring Mobile.
spring-boot-starter-validation Use for Java Bean Validation with Hibernate Validator.
spring-boot-starter-hateoas Use to build a hypermedia-based RESTful web application with Spring MVC and Spring HATEOAS.
spring-boot-starter-jersey Use to build RESTful web applications using JAX-RS and Jersey. An alternative to spring-boot-starter-web.
spring-boot-starter-data-neo4j Use for the Neo4j graph database and Spring Data Neo4j.
spring-boot-starter-data-ldap Use for Spring Data LDAP.
spring-boot-starter-websocket Use for building WebSocket. applications using Spring Framework?s WebSocket support.
spring-boot-starter-amqp Use for Spring AMQP and Rabbit MQ.
spring-boot-starter-data-cassandra Use for Cassandra distributed database and Spring Data Cassandra.
spring-boot-starter-social-facebook Use for Spring Social Facebook.
spring-boot-starter-jta-atomikos Use for JTA transactions using Atomikos.
spring-boot-starter-security Use for Spring Security.
spring-boot-starter-mustache Use for building MVC web applications using Mustache views.
spring-boot-starter-groovy-templates Use for building MVC web applications using Groovy Templates’ views.
spring-boot-starter-freemarker Use to build MVC web applications by FreeMarker views.
spring-boot-starter-batch Use for Spring Batch.
spring-boot-starter-social-linkedin Use for Spring Social LinkedIn.
spring-boot-starter-cache Use for Spring Framework’s caching support.
spring-boot-starter-data-solr Use for the Apache Solr search platform with Spring Data Solr.
spring-boot-starter-data-mongodb Use for MongoDB document-oriented database and Spring Data MongoDB.
spring-boot-starter-jooq Use for jOOQ to access SQL databases. An alternative to spring-boot-starter-data-jpa or spring-boot-starter-jdbc.
spring-boot-starter-jta-narayana Use for Spring Boot Narayana JTA Starter.
spring-boot-starter-cloud-connectors Use for Spring Cloud Connectors which simplifies connecting to services in cloud platforms like Cloud Foundry and Heroku.
spring-boot-starter-jta-bitronix Use for JTA transactions using Bitronix.
spring-boot-starter-social-twitter Use for Spring Social Twitter.
spring-boot-starter-data-rest Use for exposing Spring Data repositories over REST using Spring Data REST.

Spring Boot starters for Technical

Name Description
spring-boot-starter-tomcat Use for Tomcat as the embedded servlet container. Default servlet container starter used by spring-boot-starter-web.
spring-boot-starter-undertow Use for Undertow as the embedded servlet container. An alternative to spring-boot-starter-tomcat.
spring-boot-starter-jetty Use for Jetty as the embedded servlet container. An alternative to spring-boot-starter-tomcat.
spring-boot-starter-logging Use for logging using Logback. Default logging starter.
spring-boot-starter-log4j2 Use for Log4j2 for logging. An alternative to spring-boot-starter-logging.

Spring Boot starters for Production

Name Description
spring-boot-starter-actuator The actuator provides production-ready features for monitor, audit and manages your application.
spring-boot-starter-remote-shell CRaSH remote shell use to monitor and manage your application over SSH. Deprecated since 1.5.

Spring Boot System Requirements and Compatibility


Spring Boot required the below configuration for developing an application.

JDK Version Range

Although, Spring Boot Application can be developed with Java 6 or 7 but most recommended to use Java 8 if possible.

  • Spring Framework 5.3.x: JDK 8 to JDK 17 (expected)
  • Spring Framework 5.2.x: JDK 8 to JDK 15 (expected)
  • Spring Framework 5.1.x: JDK 8 to JDK 12
  • Spring Framework 5.0.x: JDK 8 to JDK 10
  • Spring Framework 4.3.x: JDK 6 to JDK 8

Build Tool

You can choose either build tool Maven or Gradle for developed Spring Boot Java Applications.

  • Maven 3.2+
  • Gradle [2.9, 3.x]

Servlet Containers

Spring Boot application can be deployed on any compatible servlet containers 3.0+. Here is a list of supported embedded servlet containers:

Server Name Servlet Version Java Version
Tomcat 8 3.1 Java 7+
Tomcat 7 3.0 Java 6+
Jetty 9.3 3.1 Java 8+
Jetty 9.2 3.1 Java 7+
Jetty 8 3.0 Java 6+
Undertow 1.3 3.1 Java 7+

IDE

Although Spring Boot application can be developed on IDE like NetBeans, Eclipse, etc. but most recommended IDE is STS (Spring Tool Suite).

Spring Boot Overview


Spring Boot is a Spring module that provides the RAD feature to the Spring framework. Spring Boot makes easy to create a stand-alone, production-based application that can “just run” with very little configuration. It doesn’t generate code and not require an XML configuration.

You can create a Java application that can run by command java -jar or create traditional web application by creating war and deploy on the server.

Note:

  • Spring Boot Current Version: 5.2.4 Release (February 25, 2020)
  • Written in Java
  • Website: https://spring.io/

Spring Boot Advantages

  • Spring Boot Create stand-alone Spring applications that can be started using uber jar i.e java -jar.
  • Spring Boot embed Tomcat, Jetty or Undertow directly. You don’t need to deploy WAR files explicitly
  • Spring Boot provides featured ‘starter’ POMs to simplify your Maven configuration.
  • Spring Boot automatically configures Spring dependencies whenever possible.
  • Spring Boot provides production-ready non-functional features (metrics, health checks, security and externalized configuration) by the actuator.
  • Spring Boot required no XML configuration and also not generate any code.

Spring Boot Features

  • Spring Application
  • Web Development
  • Application Events and Features
  • Externalized Configuration
  • Properties Files
  • YAML support
  • Type-safe Configuration
  • Logging
  • Security
  • Admin Features

Spring Boot Version

  • Spring Boot 0.9 Release in 2002
  • Spring Boot 1.0 Release in 2003
  • Spring Boot 2.0 Release in 2006
  • Spring Boot 3.0 Release in 2009
  • Spring Boot 4.0 Release in 2013
  • Spring Boot 5.0 Release in 2017
  • Spring Boot 5.2.4 Release on February 25, 2020

[Solved] com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘type=MyISAM’


This issue SyntaxErrorException for type MyISAM is occurred because of dialect selected for hibernate. Let’s consider my example and the issue occurred because of that.

Hibernate Configuration

<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

As we know in the hibernate configured dialect decide the query generation as per database.

Query Generated

create table ADDRESS (
       id integer not null auto_increment,
        street_name varchar(255),
        city_name varchar(255),
        state_name varchar(255),
        zipcode varchar(255),
        primary key (id)
    ) type=MyISAM

Exception Stack Trace

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
 at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
 at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlString(SchemaCreatorImpl.java:440)
 at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlStrings(SchemaCreatorImpl.java:424)
 at org.hibernate.tool.schema.internal.SchemaCreatorImpl.createFromMetadata(SchemaCreatorImpl.java:315)
 at org.hibernate.tool.schema.internal.SchemaCreatorImpl.performCreation(SchemaCreatorImpl.java:166)
 at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:135)
 at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:121)
 at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:155)
 at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72)
 at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:309)
 at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:452)
 at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710)
 at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
 at com.facingissuesonit.persistent.HibernateUtil.buildSessionFactory(HibernateUtil.java:13)
 at com.facingissuesonit.persistent.HibernateUtil.(HibernateUtil.java:8)
 at com.facingissuesonit.App.main(App.java:26)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'type=MyISAM' at line 8
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
 at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
 at com.mysql.jdbc.Util.getInstance(Util.java:381)

Solutions

As given above the problem is that the dialect org.hibernate.dialect.MySQLDialect is configured which is for MySQL 4.x or earlier version and we are pointing to MY SQL database with the newer version.

The query generated by dialect having to fragment TYPE=MyISAM that was deprecated in MySQL 4.0 and removed in 5.5. Earlier MySQL 4.x.x version use TYPE MyISAM engine used to store tables but in MySQL 5.x.x or later version MySQL is used ENGINE = MyISAM to store tables. e.g. thats make difference while hibernate generates queries.

As per the database configured for MySQL, we should use other dialects as per database configured. Here is the complete list of Hibernate dialects as per databases:

Hibernate: SQL Dialects List

For Example:
In MySQL <= 4.x.x use dialects as below

<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

In MySQL>=5.x.x. use dialects as below

<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>

Software Development Team Roles and Responsibilities


This post you will know about the peoples with different roles involved within an organization specifically for developing software or application. This software development can divide into multiple project teams based on the area of expertise, modules and do development in parallel in multiple project teams. These projects teams management for functional or operational taken care by management people like IT manager, Functional Manager, Delivery Manager, etc.

Project Team

A project team may consist of full-time and part-time resources assigned to analysis, designing, development, and testing to the deliverable of projects. As a team, these peoples have below common responsibilities that make a project team more effective.

Responsibilities

  • A clear understanding of work needs to complete.
  • Plan the activities in detail and do the assignment to the team.
  • Complete the assigned work in the budget, timeline and meet the quality expectation.
  • Inform management proactively about issues, scope changes, risk, and quality concerns.
  • Use flexible methodologies and constant changes to get the best possible results.
  • There should not be any communication gap because that can impact their understanding of the project, roles, and responsibilities of other team members.
  • Maintain a mutually supportive and foster work environment where team members understand each other’s efforts.

A project team can be under a functional organization that can involve members from the same organization or from other cross-functional organizations. To make an effective team every team member should know their responsibilities based on assigned roles.

In an organization, the software development team size and roles decide based on some common factors like outline project requirements, budget, and timeline. These requirements decide to type of resources required to fulfill those requirements within the timeline.

Generally, in software development project people involve having these roles, sometimes one role responsibility can merge with other roles also depend on organization size and budget of the project:

  1. Client/Customer
  2. Client Project Manager
  3. Project Manager
  4. Software Delivery Manager
  5. Product Owner
  6. Functional Manager
  7. Business Analyst
  8. Software Architect
  9. QA Manager
  10. Change Manager
  11. Process Analyst
  12. Test Engineer
  13. Software Developer/ Programer
  14. Subject Matter Expert
  15. Database Administrator
  16. Designer
  17. Solution Architect

1. Client/Customer

These are people that are direct beneficiaries of a product or project or service is being undertaken. These people are also called “customers” if they are internal to the organization then referred to as clients.

2. Client Project Manager

In a large project, Client Project Manager is the primary contact person that is designated as project manager for work on the client-side. If an IT manager needs any support on the client-side then Client Project manager would be responsible for those. The IT project manager and client project manager would be peers to build and implement complete solutions.

3. Project Manager

The project manager is for developing a plan, manage teams, assign tasks to project team members, recruit the right resources, lead, monitor and determine the methods and technologies to be utilized.

Responsibilities

  • Develop a project plan.
  • Manage deliverables according to the plan.
  • Recruit project staff.
  • Lead and manage the project team.
  • Determine the methodology used on the project.
  • Establish a project schedule and determine each phase.
  • Assign tasks to project team members.
  • Provide regular updates to upper management.

4. Software Delivery Manager

Delivery Manager takes care of project progress, budget and complete project delivery within the timeline.

Responsibilities

  • Serve as the primary contact person for client-related queries and concerns.
  • Review and Analyze customer orders, coordinate delivery activities set delivery priorities and make schedule adjustments to meet timely.
  • Build positive, productive and healthy working relationships with customers for business growth.
  • Analyze progress of development, defects and troubleshoot delivery issues in a timely fashion.
  • Manage a delivery team to ensure delivery of projects in a timely and accurate.
  • Oversee the progress of the delivery team and provide direction and guidance as required.
  • Perform workload assignments and resource allocation according to delivery requirements.
  • Ensure that the team maintains a high level of skills competence and operational excellence.
  • Evaluate the performance at team members and determine training needs
  • delivery goals
    • Evaluate the process  to achieve cost-effectiveness and time saving,
    • Perform customer negotiations for delivery rates.
    • Make critical business decisions to meet customer expectations.
    • Develop scope and budget for delivery projects.
    • Report project delivery status to customers and develop the required delivery artifacts.

5. Product Owner

Product owner term used in Agile Methodology. This person is the leader responsible for maximizing the value of the products created by the scrum development team.

Responsibilities

  • Acting as a primary person to coordinate with the client.
  • Define the vision of the project/product.
  • Anticipating client needs.
  • Managing the product backlog according to prioritizing needs.
  • Overseeing development stages.
  • Evaluate product progress at each iteration.

6. Functional manager

The functional manager takes care of working closely with the team members, ensuring project progress and manage ongoing responsibilities for the project.

Responsibilities

  • Assign projects to the team.
  • Work with the employee to set and coach on career goals.
  • Gather information from other Project Managers to write the evaluation.
  • Evaluate person based on work standard and performance and if a person wants to continue doing it (providing opportunities for growth)

7. Operational Manager

An operations manager is a senior role. It’s the job of overseeing organization is running as expected, check the production of goods, meeting client expectations, etc.

Responsibilities

  • Plan effective strategies, processes, policies in support of organizational goals and vision for the financial well-being of the company.
  • Coordinate, manage and monitor the workings of various departments in the organization and also evaluate performance.
  • Review financial statements and data. Utilize financial data to improve profitability.
  • Prepare and control operational budgets and Control inventory.
  • Plan the use of human resources utilization, recruitment, and placement of required staff.
  • Establish organizational structures and work schedules.
  • Delegate tasks and accountabilities.
  • Coordinate and monitor the work of various departments involved in the production, warehousing, pricing, and distribution of goods and also provide facilities required.
  • Managing quality assurance programs.
  • Setting and reviewing budgets and managing cost.
  • Research new technologies and alternative methods of efficiency.
  • Overseeing inventory, distribution of goods and facility layout.

8. Business Analyst

The Business Analyst is responsible for ensuring that the requirements of the clients are captured and documented correctly before a solution is developed and implemented. They verify the project deliverables to ensure that they meet the client’s requirements.

In many companies, Business Analysts also called as Analyst, Business Systems Analyst, Systems Analyst or Requirements Analyst.

Responsibilities

  • Bridge the gap between IT development and the business using data.
  • Assist in defining the project and translating requirements to the team.
  • Gather requirements from business units or users.
  • Document technical and business requirements.
  • Requirement specification document.
  • Performing acceptance testing.
  • Defining the scope of the project.
  • Determine requirements, Analytics to assess processes and deliver data-driven recommendations and reports to executives and stakeholders

9. Software Architect

A Software Architects design and develop software systems and applications based on client requirements.

Responsibility

  • Identifying business requirements clients and stakeholders on the project.
  • Designing the entire software system based on the received requirements from customers.
  • Choose the system architecture and each individual component of this system at a high level.
  • Choosing the right tools, technologies, and framework for the implementation of each component and connections between the components.
  • Writing project documentation and its support in a timely manner so that the overall organization can make progress before it’s complete.
  • communicate with stakeholders to make sure their application needs are being met.
  • Resolve technical problems.
  • Architectural Review.
  • Code Review.
  • Design model and also verify the qualities and performance are being met.

10. QA Manager

The quality assurance manager works with other QA (Quality Assurance) staff such as Functional Analyst and Solutions Architect to verify that the product meets the client’s requirements.

Responsibilities

  • QA converts the requirements and design documents into a set of testing cases and scripts.
  • Verify that the system meets the client’s needs.
  • Make Test Plan for test cases and scripts.
  • Make Test Plan documents as simple which provides an overview of each test case.
  • Use test cases and script to validate so that the system will not have any unexplained error.
  • Take approval from SME (Subject Matter Expert)for test plan and scripts and represents the criteria to reach a project closing.
  • Check all the test cases and script passed test status and met acceptance criteria.

Note :

  • Test scripts are step-by-step instructions on what needs to execute, what to look for, and what will result.
  • Test cases can be created with nearly on input from the architecture or design and the test scripts. Test cases are specifically shown, how a problem was solved by the software development team and it requires an understanding of not only the requirements, but also the architecture, design, and detailed design.

11. Change manager

These are a group of people usually do decision about the budget, requirements, and timeline of the project.

12. Process Analyst

Process Analyst includes process review and improvement, relationship management, product documentation, and support. The business process analyst is responsible for the business architecture and maintains artifacts.

Responsibilities

  • Process Review and Enhancement.
  • Documentation, Training, and Support.
  • Stakeholder Relationship Management.
  • Understand customer and user requirements, strategies, and goals.
  • Assess the situation of the customer organization where the projects will be deployed.
  • Facilitate modeling of the customer organization.
  • Discuss to management and facilitate a business engineering effort, if needed.
  • Perform a cost/benefit analysis for any suggested changes in the customer organization.
  • Discuss and support the marketing and sales team for the end-product of the project.

13. Test Engineer

The Test Engineer’s main responsibility is to define test cases, monitoring the test coverage, evaluate the test cycle to monitor quality and the consistent outcome. Tester is also responsible for specifying test data and evaluate the outcome of each test cycle. Test Engineer also called by name Test Analyst or Tester.

Responsibilities

  • Ensures the solution meets the business requirements and free of bug, errors, and defects.
  • Identifying the Target Test areas to be evaluated by the test effort.
  • Write the appropriate tests required and associated Test Data to execute it.
  • Gathering and managing the Test Data.
  • Evaluating the outcome of each test cycle.

14. Software Developers/Programmers

A software developer or programmer is responsible for the development and implementation of assigned tasks mentioned in design documents or user stories.

Responsibilities

  • Software Developers design, develop, and test new software programs and applications.
  • Design and update the software database.
  • Regularly communicate with management and technical support team for development.
  • Maintain and improve the performance of existing software.
  • Recommend improvements to existing software programs as necessary.
  • Test and maintain software products to ensure fulfill strong functionality and optimization.

15. Subject Matter Expert

Subject Matter Expert (SME) are specialists in specific domains and having knowledge of a discipline, technology, product, business or entire business area for specific aspects of the development.

Responsibilities

  • Review test cases for integration testing associated with the software management system.
  • Help validate user requirements for payroll application.
  • Conduct code walkthrough for accounts payable interface to a legacy system.
  • Review requirements traceability matrix, and ensure that requirements have  all code coverage.
  • Help refine and determine feasibility, correctness, and completeness of end-users ’ requirements.
  • Provide input for the design and implementation of test cases and business scenarios.
  • Help answer questions associated with the design of the status of the application, its features, and its capabilities.
  • Validate executed test results.

16. Database Administrator

A Database Administrator is a specialist that schema models, designs and creates the databases and tables used by a software solution. This role is a combination of  Data  DBA (physical) and administration (logical).

17. Designer

The application designer is responsible for understanding the business requirements clearly and designing a solution that will fulfill the business needs.

Responsibilities

  • Choose the best potential and optimum solution that will meet the client’s needs.
  •  Decide technology to create an optimum solution for the client.
  • Determine the overall model and framework for the solution, down to the level of designing screens, reports, programs and other project components.
  • Determine the data needs.
  • Handover the design and specification to programmers and other people who will implement the solution over design.

18. Solution Architect

The role of Solution Architect is used where generally SAP module customization required based on clients’ needs.

Responsibilities

  • Define the scope of the project.
  • Understand the client’s requirements and business viabilities.
  • Determine the gaps between requirements and SAP functionalities and provide workable solutions to bridge the gaps.
  • Design the solutions in detail with the help from the consultants and business.
  • Plan the closure of the solutions and see through the implementation of the solutions.

 

[Solved] TESSDATA_PREFIX environment variable is set to the parent directory of your “tessdata” directory.


This exception happen when you trying to read text of image by using tessdata API’s. It try to get defalt path of environment variable TESSDATA_PREFIX in you application root diectory/tessdata/lang.traineddata. but if this folder and file not found then throw below exception.

Stacktrace


Exception in thread "main" java.lang.Error: Invalid memory access
    at com.sun.jna.Native.invokePointer(Native Method)
    at com.sun.jna.Function.invokePointer(Function.java:470)
    at com.sun.jna.Function.invoke(Function.java:404)
    at com.sun.jna.Function.invoke(Function.java:315)
    at com.sun.jna.Library$Handler.invoke(Library.java:212)
    at com.sun.proxy.$Proxy0.TessBaseAPIGetUTF8Text(Unknown Source)
    at net.sourceforge.tess4j.Tesseract.getOCRText(Tesseract.java:437)
    at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:292)
    at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:213)
    at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:197)
    at com.fiot.ImageTextReading.crackImage(ImageTextReading.java:22)
    at com.fiot.ImageTextReading.main(ImageTextReading.java:10)
    
Error opening data file ./tessdata/eng.traineddata
Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "tessdata" directory.
Failed loading language 'eng'
Tesseract couldn't load any languages!
    

Solutions

Follow these steps to resolve this issue:

  1. First download tessdata from this location https://github.com/tesseract-ocr/tessdata .
  2. Rename this unzip folder to tessdata.
  3. Copy this folder and paste it to your applciation root directory.

For all steps and environment setup follow this example: Java : Read Text from and Image Example

[Solved] java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path


This IllegalStateException for these jar conflict happens when you choose library in you class path that are internally use log4j and slf4j.

In theory, If you are using log4j for logging, you could simply exclude the log4j-over-slf4j.jar because by using log4j,hacking other code to route the log4j calls to slf4j can lead to recursion and hence the strict check is there.

Stacktrace


Exception in thread "main" java.lang.ExceptionInInitializerError
    at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:72)
    at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:45)
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
    at net.sourceforge.tess4j.Tesseract.(Tesseract.java:76)
    at imageread.ImageTextReading.crackImage(ImageTextReading.java:17)
    at imageread.ImageTextReading.main(ImageTextReading.java:9)
Caused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError. See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.
    at org.slf4j.impl.Log4jLoggerFactory.(Log4jLoggerFactory.java:54)
    ... 9 more

Solutions

From your class path or pom.xml exclude dependencies for log4j and slf4j as below.

In case of maven


<exclusions>
  <exclusion> 
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
  </exclusion>
  <exclusion> 
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
  </exclusion>
</exclusions>

Incase of Gradle


compile('org.xxx:xxx:1.0-SNAPSHOT'){
    exclude module: 'log4j'
    exclude module: 'slf4j-log4j12'
}

Java: Read Text from an Image


Java provides net.sourceforge.tess4j library to read and extract text from the image. It makes developer life easy for applications where image reading is required.

Example of Reading/Extract Text from Image

  1.  In the hospital, If you have scanned your doctor given a prescription and then some hospitals maintain patient records based on detail. then in the next visit after so many days, if you forget to carry it and the doctor asked about the previous prescription then based on your mobile number, name or date can reprint your doctor prescribed detail.
  2. In Big Data where need to do some analysis based on the above cases can extract detail from images and show reports.

How Text Reading from image works?

In an image extracting text means finding out the text components and then extract the geometric shape components. These text components are extract with geometric components as well and the relationship between these components built up by flow lines between components. These extracted components are a form of metadata (XML format), stored in a knowledge base or shared with others.

Environment Setup

Download tessdata from below git directory and rename to tessdata. Place this folder to your application root directory as below.

https://github.com/tesseract-ocr/tessdata

Read Text from Image Directory

Dependency

Add below dependency in your you application pom.xml


    <dependency> 
        <groupId>net.sourceforge.tess4j</groupId> 
        <artifactId>tess4j</artifactId> 
        <version>3.2.1</version> 
    </dependency>

 

Java Code to Read Text from Image

In this example, you will see complete steps to read/extract text from an image.

Sample Image

test image

Java Code

In this below image you will see complete java lines of code to extract text from the image and output of sample image.

Java Code to Read Text from Image

DBMS VS RDBMS


RDBMS is extension of DBMS.

DBMS (Database Management System)

Software that provides a systematic way of creating, retrieving and managing data in a database.

DBMS Example : File System, XML, Dbase, Microsoft Access, LibreOffice Base, Fox Pro etc.

RDBMS(Relational Database Management Information System)

A DBMS based on relational model and store data in tables that related to each other.

RDBMS Example: MySQL, PostGre, SQL Server, Oracle, MariaDB, SqlLite etc.

Here area some main points that make differences between DBMS and RDBMS.

DBMS RDBMS
DBMS application stores data in files that have no relationship. RDBMS application stores data in tabular form which will have a relation between tables.
DBMS store data either in hierarchical form or navigational form. RDBMS table has one identifier called as primary key and data stored in tabular form.
DBMS does not support Normalization. RDBMS supports normalization.
DBMS does not provide any security with regards to data manipulation. RDBMS defines the integrity constraints for the purpose of ACID property.
DBMS does not support distributed database. RDBMS support distributed database.
DBMS is for small organization to deal with small data. It supports for single user. RDBMS is designed to handle large amount of data. It supports multiple users.
DBMS does not support client server architecture. RDBMS  support client server architecture.
DBMS have high data redundancy. RDBMS have low data redundancy.
DBMS takes more time to access data. RDBMS takes less time to access data.

ACID Vs BASE for Database Transactions


In the previous post, you have learned about the ACID and BASE properties of database transactions in detail.

ACID vs BASE

Here you will know about high-level differences between ACID and BASE.

 

ACID BASE
Provides Vertical Scaling Provides Horizontal Scaling
Strong Consistency Weak Consistency – Stale Data OK
Isolation Last Write Wins, availability first
Transaction Programmer Managed
Available/Consistent Available/Partition Tolerant
Robust Database/Simple Code Simpler Database, Harder Code
Focus on “Commit” Best Effort
Nested Transactions Approximated Answers
Less Availability Aggressive (optimistic)
Conservative (pessimistic) Simpler
Difficult Evaluation(i.e Schema) Faster, Easier evolution
High Maintenance Cost Low Maintenance Cost
Expensive Joins and Relationship Free from joins and Relationship
Examples: Oracle, MySQL, SQL Server, etc. Example : DynamoDB, Cassandra, CouchDB, SimpleDB etc.

See Also:

SQL vs NoSQL


In this post you will know about the main high level difference between SQL and NoSQL type databases.

SQL vs NoSQL

SQL NoSQL
Relational Type Non-Relational Type
Structured Data Stored in Tables The un-structured data store in JSON format in file but graph of database show relationship.
Strict Schema Dynamic Schema
Vertical Scalable Horizontal Scalable
Structured Query Language Un-structured Query Language
ACID Transactions CAP Theorem
Requires downtime In most cases automatic, No outage required
Rigid schema bound to the relationship Non-rigid schema and flexible.
Helpful to design complex queries. No joins relationship, no any powerful tool to prepare complex queries.
Recommend and best suited for OLTP (Online Transactional Processing) Systems. Less likely to be considered for the OLTP System.
Storage : Table (Row->Entity, Column->Attribute)
RDBMS: Oracle, MYSQL, SQL Server, IBM DB2 etc.
Storage:
Key-Value: Redis, Dynamo
Document: MongoDB
Graph: Neo4j, InfiniteGraph
Wide-column- Cassandra, HBASE
SQL is not fit for Hierarchical work. NoSQL is the best fit for hierarchical work as it follows the key-value pair’s way to store values.

BASE Properties for Distributed Database Transactions


In the previous post, you have learned about ACID properties of the database transactions for traditional databases. As transactions are growing over the internet, systems are scalable and distributed. In some of the systems where availability is more important than the consistency.

For Example, Amazon, eBay, etc.

For such types of systems in 2000, Eric Brewer’s introduce a theorem that’s called CAP Theorem. It states that

“In a distribution system can only have two out of following three Consitentency, Availability, and Partition Tolerance- One of them must be a sacrifice. You can’t promise all three at a time across reading/write requests.”

Based on CAP theorem, where scalability and availability is most important. It introduces alternatives to ACID is BASE for distributed database transactions.

BASE full form:

BASE

Basically Available

The system guarantees availability.

It majorly focuses on availability, potentially with outdated data and it does not provide guarantee on global data consistency across the entire system.

Soft-state

The state of the system may change over time.

Even without explicit state updates, data may change due to the asynchronous propagation of updates and nodes that become available.

Eventual consistent

The system will eventually become consistent.

Updates eventually propagated, the system would reach in a consistent state if no further updates and network partitions fixed.

See Also:

12 Software Design Key Principles


If you are in software development and working as senior programmer or application architect then you should keep these software deigning principle in your mind while working on software or application development.

Why Software Design Principles?

Software Design principles are set of guidelines to handle complexity and reduce effort needed to develop a good system design. Design principles ease problems of future development, enhancement, maintenance and also reduce the scope of error during design.

What are Software Design Principles

These are the key software design principles but most important is SOLID (top 5)  which use in all software designing.

  1. Single Responsibility Principle : One class should do one thing and do it well.
  2. Open Close Design Principle : Open for extension, close for modification.
  3. Liscov Substitution Principle : Sub type must be substitute for super type.
  4. Interface Segregation Principle: avoid monolithic interface , reduce pain on client side.
  5. Dependency Inversion Principle: Don’t ask lets framework give it to you.
  6. DRY(Don’t Repeat Yourself) : avoid duplication in code.
  7. KISS (Keep it Simple, Stupid) : Keep you code simple, small and understandable.
  8. Encapsulate what changes : hides implementation detail helps in maintenance.
  9. Favor Composition over inheritance: Code reuse without cost of inflexibility.
  10. Programming for interface : Helps in maintenance, improve flexibility.
  11. Delegation Principle: Don’t do all things by your self. Lets Delegate it.
  12. YAGNI ( You Ain’t Gonna Need It) : If it’s not in the concept, it’s not in the code

All these software design principles are mainly based on four factors:

  1. Problem Partitioning : Divide the problem in manageable pieces.
  2. Modularity : Divide software to well-defined separate module .
  3. Abstraction: Provide component as interface and hide internal implementation.
  4. Strategy Of Design: Top-Down/Bottom-Up Approach

In this further section will discuss about in these principles in detail.

1 : Single Responsibility Principle (SRP)

      A class should have only one reason to change. If there is any other reason create another class.

This principle is completely based on Coupling and Cohesion. This principle states that In your software design a classes should in such a way that each class should have a single purpose/responsibility/functionality.

While designing software if you put more than one functionality in single class then increase coupling between functionalities. If change required in one functionality there are chances to broke other functionality and required more testing to avoid such surprises in production environment.

 Responsibility Examples

Suppose you are having JPA classes as  SavingAccountRepository.java and CurrentAccountRepository.java then SavingAccountRepository.java class should have only methods and queries related with Saving Accounts. It means your class should specialize in single purpose.

Others most common example of responsibilities:

  1. Logging
  2. Formatting
  3. Validation
  4. Notification
  5. Error Handling
  6. Parsing
  7. Caching
  8. Mapping
  9. Class Section/ Instantiation etc.

Benefits:

  • This principle make your software easier to implement and prevent unexpected side-effects of future changes.
  • Your class will change only if anything will change in respected responsibility.
  • Need to update dependencies and compile when some respected dependencies change.
  • Reduce coupling between software and components.

The Single Responsibility Principle (SRP) also provides other benefits with classes, components and micro services with single responsibility make your code easier to explain, understand, implement. It also improves development speed and easier to track bugs.

2 : Open Close Principle (OCP)

Software entities like classes, modules and functions should be open for extension (new functionality) and closed for modification.

This principle is based on  inheritance or composition design pattern like Strategy Design pattern. As per this principle:

  • “Open” means , Your code  should be able to extend existing code in order to introduce new functionality.
  • “Close” means, Once your module has been developed and tested, the code will change only when correct bugs.

For Example: A BankAccount.java base class contains all basic transaction related properties and methods. The same class can be extended by SavingAccount.java and CurrentAccount.java to handle saving and current account functionalities. If new functionalities need to add then only modification required in BankAccount.java class. Hence this class is open for extension and close for modification.

Benefits:

  • The main benefit of Open/Close Design principle is that already developed and tested code will not modified and don’t break.

3 : Liscov Substitution Principle (LSP)

Drived type must be completely substitute of their base type.

Liscov Substitution Principle is closely related to the Single Responsibility Principle and Interface Segregation Principle.

This principle states that Subclasses or derived classes should be completely substituted of superclass. The Subclass should enhance the functionality but not reduce it.

In other words, functions that use pointers and reference of base classes must be able to use objects derived classes without knowing it.

Example

Suppose Employee class extends Person Class by inheritance. In this way wherever you are using person class should also be able to use Employee class because Employee is a subclass of Person class.

Benefits

  • If this principle violates then so much extra conditional code of type checking and duplicate code need to write throughout the application that can cause bugs when the application grows.
  • In methods or functions which use the superclass type must work with the object of subclass without any issue.

4 : Interface Segregation Principle (ISP)

Clients should not be forced to depend on methods in interfaces that they don’t use.

This principle states that a client should not implement an  interface if it doesn’t use that.  An interface should belong to clients , not to library or hierarchy and keep only those methods as required for client.

Example

In an application service interface exposed to client should have only those methods that are related to client.

Benefits

  • If you violate this principle and add some more methods in interface that are not used with client then if you change any thing in interface definitely some functionality of client will break.

5:  Dependency Inversion Principle (DIP)

High level module should not depend on low level module , both should depend on abstractions. Abstraction should not depend on detail. detail should depend on abstraction.

This principle provide loose coupling between  the dependencies of modules and classes.

The Dependency Inversion Principle states that:

  1. High level modules should not depend on low level modules directly, both should depend on abstractions.
  2. This abstraction should not depend on details, details should depend on abstractions.

Examples

The best example of Dependency Inversion Principle is Spring framework where dependencies are injected through XML or Annotation which provide abstractions and can change with out modification on implementation.

Benefits

  • If you violate this principle your code will be tightly coupled because every high level module is directly referencing to lower level modules.
  • Makes testing easy by injecting the mock objects with out modification on existing functionality.

6: Don’t Repeat Yourself (DRY)

          Avoid duplication of code.

This principle states that don’t write duplicate code. If you have same code on multiple places then consider making a separate method. or If you are using any hard code value more than one time make this value as public static final constant.

Example

Suppose, you are using some format to validate orderId and your complete system is based on it. In future, if your orderId format get change and if your code is duplicate then you have to modify in all places otherwise system will fail. In such scenarios better write hardcoded values and common code in methods so that make system maintenance easy.

Benefits

  1. The main benefit of DRY principle is maintenance of system.
  2.  This helps to design a system scalable, maintainable and reusable.
  3.  Common functionality or utility methods will on one place.

7 : Keep it Simple, Stupid (KISS)

Keep it short, simple and Understandable.

KISS principle states that always try to keep your code in small pieces, simple and avoid unnecessary complexity.

Benefits

  • KISS principle helps to write easy maintainable code.

DRY and KISS principle are almost similar because it focus on small piece of code but difference is KISS principle more focused on simplicity and avoid complexity.

8 : Encapsulate What Changes

Hidden implementation detail helps in maintenance.

This principle states that encapsulate the code you expect or suspect to be changed in future. By default make your variables and methods private and increase access step by step like from private to protected not directly public.

Example

In java lots of design patterns use encapsulated code , like Factory Design Pattern is one example where object creation code is inside factory class and in future need to enhance functionality for any new product then do it without impact of existing code.

Benefits

  • It’s easy to test and maintain proper encapsulated code.

9: Favor Composition Over Inheritance

Code reuse without cost of inflexibility.

In OOPS there are two ways to reuse the code, Inheritance and composition, both the ways have own advantage and disadvantage.

This principle states that, If possible always prefer composition over inheritance because composition are lot more flexible than inheritance.

Benefits

  •  Composition allow to change behavior of class at runtime by setting properties during runtime and by using interfaces to compose a class by runtime polymorphism provides flexibility to use better implementation any time.

10 : Programming for Interface

This principle states that we should always program for interface not for implementation. It makes code flexible with any implementation of the interface.

In other words, We should always use interface type in variable, methods arguments and return type of methods like Super class type to object instead of sub class.

Example

Programming for Interface Example

Benefits

  • It provides flexibility to maintenance code and change implementation.

11 : Delegation Principle

Don’t do all things by yourself, Lets delegate it

This principle states that don’t all things in yourself, we should write logic to delegate it to respective class.

Example

  •  Event delegation, where an event is delegate to handlers class for handling.
  •  equals() and hashcode() methods compare two objects for equality. Here we ask class inself to do comparison instead of Client class doing that check.

Benefit

  •  No duplication of code.
  •  Pretty easy to modify behaviour.

12 : You Ain’t Gonna Need It (YAGNI)

                 If it’s not in the concept, Not in the code.

YAGNI principle state that we should implement things when we need then never implement things before need them.

Benefit

  • If we violate this principle and write unnecessary code with perception like may required in future then unnecessarily have to take care while maintenance or some change happen.

CAP Theorem


Now a days, most of the enterprise based applications are distributed (a collection of interconnected nodes that shared data) over the internet/cloud so that increases the availability of systems. As the application grows and in terms of users and transactions counts and required persistence than big concern is database scalability.

After considering such facts In the year 2000, Eric Brewer developed one theorem that is called as CAP Theorem or Brewer’s conjecture.

CAP Theorem, states that:

“In a distribution system can only have two out of following three Consitentency, Availability, and Partition Tolerance- One of them must be a sacrifice. You can’t promise all three at a time across reading/write requests.”

  • Consistency: Every read request receives the most recent write or an error.
  • Availability: Every request should receive a (non-error) response, without the guarantee that it contains the most recent write.
  • Partition Tolerance: The system continues to work despite an arbitrary number of messages being dropped/delayed by the network between nodes/partitions.

Cap Theorem

In the CAP theorem, consistency is quite different from the ACID database transactions. In distributed systems, partition tolerance means the system will work continue unless there is a complete network failure. If a few nodes fail then the system should keep going.

CAP Theorem Example

You can decide your system technologies based on your primary importance for Consistency, Availability and Partitioning Tolerance. Here we are just taking one example base on database selection:

CA (Consistency + Availability) Type

In this system consistency and availability is primary constraints but such type of system not provide a guarantee of one of the system is offline then the whole system is offline. Otherwise, some of the nodes will not consistent and also not have the latest information.

For Example, Oracle and MySQL are good with Consistency and Availability but not partition tolerant.

CP (Consistency + Partition Tolerant) Type

In this system, consistency and partition tolerance is primary constrains but such a system not provide a guarantee for availability and throws an error as long as the partitioned state not resolved.

For Example, Hadoop and MongoDB stored redundant data in multiple slave nodes and it tolerates an outage of a large number of nodes in the cluster.

AP (Availability + Partition Tolerant) Type

Such a system can not guarantee consistency because if updates can be made to either of a node if some nodes or network issues. This system can have different values on different nodes.

For Example, CouchDB, Dynamo DB, and Cassandra PA type database.

Note CouchDB and Dynamo DB store values in key-value pairs while Cassandra store values in the form of a column family.

See Also:

References

ACID Properties for Database Transactions


ACID is one of the main concepts or compliance to handle transactions in relational database systems (RDBMS). Full form of the ACID acronym is :

ACID

Here you will know about these concepts in detail:

Atomicity

Each Database transaction must completely succeed or failure/rolled back.

This concept state that partially success not allowed. Each transaction should completely successful or failed. Suppose your transactions have multiple steps (either read or write ) to perform operations in the database then if one operation gets failed then your database will return in the same state it was before starting the transactions.

Consistency

A transaction can not leave the database in an inconsistent state.

This concept state that if your data is replicated across multiple nodes(copies of the database) then these nodes should have the same information.

Isolation

One transaction can not interfere with Others.

This concept state that one client database transactions should not interfere with other client transactions. If one transaction is taking place for the same records then other transactions should wait.

Durability

Completed transactions should persist, even when servers restart etc.

This concept states that once your transaction got completed then this information should not be lost even system is powered off or restart. It should store in nonvolatile storage like the hard drive.

ACID Example

The best example of an ACID is transferring money from one account to another account. There may be two databases with different banks, so this transaction will perform withdrawal from one account while depositing on another account. If one of the steps got failed then return both database state to initial from where get started. The balance should be consistent on all nodes and if someone also performing some transaction at the same time that should be in the waiting state so that it keeps it isolated. If the transaction got completed it should durable by maintaining state in data.

In the case of ACID, other transactions must wait to complete the current transaction. This waiting causes the performance issue. In this case for maintaining consistency and improve performance, the solution is vertical scaling so that getting more get more powerful systems to process each transaction in less time and become available to process other requests.

See Also:

[Solved] javax.naming.NameNotFoundException: MyXYZConnectionFactory not found


javax.naming.NameNotFoundException: MyXYZQueueConnectionFactory not found error occurred when JNDI name trying to configured it not exist on provider or some mismatch with name.

For Example:
In this example, I was trying to get MyXYZQueueConnectionFactory while factory on provider JNDI name is given as MyQueueConnectionFactory.

Stacktrace of Error


Binding name:`java:comp/env/jms/QueueName `
Binding name:`java:comp/env/jms/MyQueueConnectionFactory `
JNDI lookup failed: javax.naming.NameNotFoundException: MyXYZQueueConnectionFactory not found
Unbinding name:`java:comp/env/jms/QueueName `
Unbinding name:`java:comp/env/jms/MyXYZQueueConnectionFactory `

Solutions

  • Check for JNDI name and factory created on configured server.
  • Check name of JNDI and factory is same as you want to pint on server.

[Solved] JMSInitialContext: Unable to get the internal JNDI context


JMSInitialContext: “Unable to get the internal JNDI context” error occurs when the developer/ config person has incorrectly specified the client properties file.

For Example: A developer might have used the windows syntax for path in a unix system environment. This error can also occurred when the correct path to the app.properties file is not correct.

Solutions

The developer/config person has to define the path to the config directory properly and defined JNDI should be available.

Stacktrace of Error


java -Djms.properties=%J2EE_HOME%\config\app.properties MyQueueSender MyFIOTQueue

Queue name is MyFIOTQueue


SEVERE JMSInitialContext: Unable to get internal JNDI context because:
javax.naming.CommunicationException: Cannot connect to ORB [Root exception is
org.omg.CORBA.COMM_FAILURE: minor code: 789479689 completed: No]
This error can be rectified by the user setting the class path for the client application correctly.

[Solved]com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table ‘ABC’ doesn’t exist


“com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table ‘test.stock’ doesn’t exist” this exception in hibernate generally occured when mentioned table in mapping(hbm.xml) or JPA annotated entity table not exist in database. Sometime table exist in database but table with mentioned catalog or schema (due to copy paste or typing mistake) doesn’t exist.

Problem

In this case issue is “com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table ‘test.stock’ doesn’t exist”. This issue is because of ‘test.stock’ table is not find out because here in put mentioned catalog as “test” that is schema or database name while in hibernate.cfg.xml mentioned schema name as facingissuesonitdb.

Input Stock.hbm.xml


<hibernate-mapping>
    <class name="com.facingissuesonit.model.Stock" table="stock" catalog="test">
    <id name="stockId" type="java.lang.Integer">
            <column name="STOCK_ID" />
            <generator class="identity" />
        </id>
        <property name="stockCode" type="string">
            <column name="STOCK_CODE" length="10" not-null="true" unique="true" />
        </property>
        <property name="stockName" type="string">
            <column name="STOCK_NAME" length="20" not-null="true" unique="true" />
        </property>
     
    </class>
</hibernate-mapping>
     

Exception StackTrace


ERROR: Table 'test.stock' doesn't exist
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test.stock' doesn't exist
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.Util.getInstance(Util.java:381)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3558)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3490)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2109)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2643)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2077)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2362)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2280)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2265)
    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:384)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:205)
    ... 22 more

Solutions

  • Solution 1: Replace above xml attribute catalog value from “test” to “facingissuesonitdb” as used same in hibernate.cfg.xml.
  • Solution 2: If your application is using only one database/schema then recommendation is to mention schema name in hibernate.cfg.xml so that in future if your schema name get change only configuration file need to update not all mapping files.
    
    <property name="hibernate.default_schema">'facingissuesonitdb'</property>
    

[Solved]org.hibernate.MappingException: Unknown entity: XYZ


“org.hibernate.MappingException: Unknown entity” this exception occurred when you are using an entity in Hibernate session but with respect to that entity mapping file (hbm.xml) is not defined or used an POJO class with out any JPA/Hibernate annotations.

Example


org.hibernate.MappingException: Unknown entity: com.facingissuesonit.model.Stock
    at org.hibernate.metamodel.internal.MetamodelImpl.entityPersister(MetamodelImpl.java:620)
    at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1634)
    at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:104)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)
    at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)
    at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)
    at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:689)

Solutions

In my case, I used an entity Stock in hibernate session but forget to add my Stock.hbm.xml file mapping in hibernate.cfg.xml file. When I added this line of statement in my hibernate.cfg.xml then problem resolved.

Problem: Hibernate was trying to find out the mapping for used entity Stock.java in all defined XML and not able to get that’s what throw exception.
Add this line in hibernate.cfg.xml



Java Program: Print characters having prime frequencies in order of occurrence


Question : Print characters having prime frequencies in order of occurrence

Given a string str containing only lowercase characters. The task is to print the characters having prime frequency in the order of their occurrence. Note that repeated elements with prime frequencies are printed as many times as they occur in order of their occurrence.

Examples:

  • Input: str = “facingissuesonit”
    Output: facingissuesonit Frequency
    ‘f’ 1
    ‘a’ 1
    ‘c’ 1
    ‘i’ 3
    ‘n’ 2
    ‘g’ 1
    ‘s’ 3
    ‘u’ 1
    ‘e’ 1
    ‘o’ 1
    ‘t’ 1

    ‘i’, ‘n’ and ‘s’ are the only characters with prime frequencies.
    Output: insinsis

  • Input: str = “aeroplane”
    Output: aeae

Algorithm

  • Step 1: Ask the user to input String
  • Step 2: Get count of each character occurrence and insert in character-based sorted map
  • Step 3: Remove Character those occurrences are not Prime
  • Step 4: Print Character in alphabetical order and reduce the count by one
  • Step 5: Remove an entry from the map if the count is zero
  • Step 6: Repeat step 4 and 5 until map get empty

Java Program

 

public class Program2 {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);
System.out.print("Enter a text String: ");
String inputStr = input.nextLine();
System.out.println("Result :" + primePlacesString(inputStr));
}

private static List primePlacesString(String inputStr) {
List charList = null;
char[] chars = inputStr.toCharArray();
// Enter Character and respected occurence in map
TreeMap map = new TreeMap();
for (Character c : chars) {
if (map.get(c) == null) {
map.put(c, 1);
} else {
map.put(c, map.get(c).intValue() + 1);
}
}
// Removed character those occurence are not prime
Character[] keys = (Character[]) map.keySet().toArray(new Character[map.size()]);
for (Character key : keys) {
if (!isPrimeNumber(map.get(key))) {
map.remove(key);
}
}
// get list of character in sequence as per counts
if (map != null && !map.isEmpty()) {
charList = new ArrayList();
printMapInSquence(map, charList);
}
return charList;
}

// Code to check number is prime or not
private static boolean isPrimeNumber(Integer number) {
boolean isPrimeNumber = true;
if (number == 0 || number == 1) {
isPrimeNumber = false;
} else {
for (int i = 2; i <= number / 2; i++) {
if (number % i == 0) {
isPrimeNumber = false;
break;
}
}
}

return isPrimeNumber;
}

private static void printMapInSquence(Map map, List charList) {
if (map != null && !map.isEmpty()) {

Character[] keys = (Character[]) map.keySet().toArray(new Character[map.size()]);
for (Character key : keys) {
charList.add(key);
if (map.get(key) == 1) {
// remove characters those are already printed and count are 1
map.remove(key);
} else {
// reduce counts of printed characters and counts more than one
map.put(key, map.get(key) - 1);
}
}
printMapInSquence(map, charList);
}
}

}

Output


Enter a text String: facingissuesonit
Result :[i, n, s, i, n, s, i, s]

Enter a text String: aeroplane
Result :[a, e, a, e]

 

[Solved]org.hibernate.exception.SQLGrammarException: could not execute statement


“org.hibernate.exception.SQLGrammarException: could not execute statement” this exception generally occurred when there is some issue with generated query grammar or syntax. Actual reason of issue you will in exception stacktrace cause.

Problem

In this case issue is “com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table ‘test.stock’ doesn’t exist”. This issue is because of test.stock table is not find out because here input mapping xml file having catalog as “test” that is schema or database name while in hibernate.cfg.xml mentioned schema name as facingissuesonitdb.

Input Stock.hbm.xml


<hibernate-mapping>
    <class name="com.facingissuesonit.model.Stock" table="stock" catalog="test">
    <id name="stockId" type="java.lang.Integer">
       <column name="STOCK_ID" />
       <generator class="identity" />
    </id>
    <property name="stockCode" type="string">
           <column name="STOCK_CODE" length="10" not-null="true"     unique="true" />
    </property>
    <property name="stockName" type="string">
            <column name="STOCK_NAME" length="20" not-null="true" unique="true" />
    </property>
</class>
</hibernate-mapping>

Exception StackTrace


ERROR: Table 'test.stock' doesn't exist
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute statement
    at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
    at org.hibernate.dialect.identity.GetGeneratedKeysDelegate.executeAndExtract(GetGeneratedKeysDelegate.java:57)
    at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:42)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2909)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3480)
    at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)
    at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:626)
    at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:280)
    at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:261)
    at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:306)
    at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:318)
    at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:275)
    at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:182)
    at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:113)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)
    at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)
    at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)
    at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:689)
    at org.hibernate.internal.SessionImpl.save(SessionImpl.java:681)
    at org.hibernate.internal.SessionImpl.save(SessionImpl.java:676)
    at com.facingissuesonit.App.main(App.java:29)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test.stock' doesn't exist
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.Util.getInstance(Util.java:381)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3558)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3490)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2109)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2643)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2077)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2362)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2280)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2265)
    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:384)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:205)
    ... 22 more

Solutions

  • Solution 1: Replace above xml attribute catalog value from “test” to “facingissuesonitbd” as used same in hibernate.cfg.xml.
  • Solution 2: If your application is using only one database/schema then recommendation is to mention schema name in hibernate.cfg.xml so that in future if your schema name get change only configuration file need to update not all mapping files.
    
    <property name="hibernate.default_schema">facingissuesonitdb</property>
    

Java Program : Get all possible values of X such that A % X = B


Question:  Write a java program to get  all possible values of X such that A % X = B. Input two integers A and B. The task is to find the  all possible values X such that A % X = B. If there are infinite number of possible values then print -1.

Examples:

  1. Input: A = 21, B = 5
    Output: 2
    8 and 16 are the only valid values for X.
  2. Input: A = 5, B = 5
    Output: -1
    X can have any value > 5

Algorithm

  • Step 1: Ask the user to input values of A and B
  • Step 2: Find out all possible factors of (A-B) which are greater than B
  • Step 3: Use StringJoiner to print the possible value in comma separated form.

Java Program

public class Program1 {
public static void main(String[] args) {
System.out.println("Enter values of A and B to get possible values of X from expression A % X = B");

Scanner input = new Scanner(System.in);
System.out.print("Please Enter an integer A: ");
int A = input.nextInt();

System.out.print("Please Enter an integer B: ");
int B = input.nextInt();

System.out.println("Possible Values of X :" + getAllowedValues(A, B));
}

private static String getAllowedValues(int A, int B) {
//Use to print value in comma separated form
StringJoiner joiner = new StringJoiner(",");

if (A - B > 0) {
//find out all possible factor of(A-B) which are greater than B
for (int C = (A - B); C > 0 & C > B; C /= 2) {
if ((A - B) % C == 0)
joiner.add(Integer.toString(C));
}
} else {
joiner.add("-1");
}
return joiner.toString();
}

}

Output


Enter values of A and B to get possible values of X from expression A % X = B
Please Enter an integer A: 21
Please Enter an integer B: 5
Possible Values of X :16,8

Enter values of A and B to get possible values of X from expression A % X = B
Please Enter an integer A: 5
Please Enter an integer B: 5
Possible Values of X :-1

[Solved] Fortify Issue “Log Forging” and “Cross Site Script Injection” in log file


To fix fortify scan “Log Forging” or “Cross Site Script Injection” issue need to remove script tag before printing log message in console or log file.

Why?

If logs statement having script tag then open these logs over browser like kibana while analysis. The script or content inside the script tag can execute that cause “cross-site script injections”.

Solutions

Call this lines of code which below uses a regular expression to identify valid script tags and removes them from the message while leaving the script code between the starting and end tags.

Remove script tag from log string message

[Solved] Maven Error on Eclipse/STS : Could not calculate build plan org.apache.maven.plugins:maven-jar-plugin:jar:2.4


This maven error generally happen when create maven based web project by using “maven-archtype-console” which generally try to import all library automatically.

You will see this complete error message on pom.xml


Could not calculate build plan: Plugin org.apache.maven.plugins:maven-jar-plugin:2.4 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-jar-plugin:jar:2.4

maven error

POM.XML



  4.0.0
  com.FacingIssuesOnIT
  Spring-Core-Examples
  0.0.1-SNAPSHOT
  Spring-Core-Examples
  Spring Core Exammples

Solution 1:

You need just to follow those steps:
Right Click on your project: Run (As) -> Maven clean
Right Click on your project: Run (As) -> Maven install
After which, if the build fails when you do Maven Install, it means there is no web.xml file under WEB-INF or some problem associated with it.

Solution 2:

Right click on project-> Maven->Click checked box ‘Force Update’->Update

[Solved] Maven Error on Eclipse/STS : Failure to transfer org.apache.maven.plugins:maven-surefire-plugin:pom:2.12.4


This maven error generally happen when create maven based web project by using “maven-archtype-webapp” which generally try to import all library automatically.

You will see this complete error message on pom.xml


Description Resource Path Location Type Failure to transfer org.apache.maven.plugins:maven-surefire-plugin:pom:2.12.4 from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven.plugins:maven-surefire-plugin:pom:2.12.4 from/to central (http://repo.maven.apache.org/maven2): The operation was cancelled. pom.xml /SpringCoreTuto line 1 Maven Configuration Problem

POM.XML


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.fiot.example</groupId>
  <artifactId>SpringCoreTuto</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>SpringTuto Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>SpringCoreTuto</finalName>
  </build>
</project>

Solution 1:

You need just to follow those steps:
Step 1: Right Click on your project: Run (As) -> Maven clean
Step 2: Right Click on your project: Run (As) -> Maven install
After which, if the build fails when you do Maven Install, it means there is no web.xml file under WEB-INF or some problem associated with it.

Solution 2:

Right click on project-> Maven->Click checked box ‘Force Update’->Update

[Solved] javax.crypto.AEADBadTagException: Tag mismatch


AEADBadTagException is subclass of BadPaddingException. It’s occurred when a Cipher unable to verify the authentication tag. It’s occurred when Cipher is AEAD i.e GCM/CCM mode.

public class AEADBadTagException extends BadPaddingException

Constructor

  • AEADBadTagException(): Constructs a default constructor of AEADBadTagException with no detail message.
  • AEADBadTagException(String msg): Constructs a message constructor of AEADBadTagException with the specified detail message.

Exception

Here is a complete example of encryption and decryption based on algorithm AES/GCM/NoPadding but having an issue because of IV value which is used for authentication.

import java.security.SecureRandom;
import java.util.Base64;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;<span id="mce_SELREST_start" style="overflow:hidden;line-height:0;"></span>
/**
* example for plain text encryption and decryption by using Java AES 256 GCM Encryption Algorithm
*/
public class AES_GCM_Example
{
        static String plainText = "facing Issues on IT  (Learn from Others Experience)";
           public static final int AES_KEY_SIZE = 256;
           public static final int GCM_IV_LENGTH = 12;
           public static final int GCM_TAG_LENGTH = 16;

           public static void main(String[] args) throws Exception
           {
               KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
               keyGenerator.init(AES_KEY_SIZE);

               // Generate Key
               SecretKey key = keyGenerator.generateKey();

               byte[] IV = new byte[GCM_IV_LENGTH];
               SecureRandom random = new SecureRandom();
               random.nextBytes(IV);

               System.out.println("Original Text : " + plainText);

               byte[] cipherText = encrypt(plainText.getBytes(), key, IV);
               System.out.println("Encrypted Text : " + Base64.getEncoder().encodeToString(cipherText));

               String decryptedText = decrypt(cipherText, key, IV);
               System.out.println("DeCrypted Text : " + decryptedText);
           }

           public static byte[] encrypt(byte[] plaintext, SecretKey key, byte[] IV) throws Exception
           {
               // Get Cipher Instance for selected algorithm
               Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");

               // Create SecretKeySpec for key
               SecretKeySpec keySpec = new SecretKeySpec(key.getEncoded(), "AES");

               // Create GCMParameterSpec for key
               GCMParameterSpec gcmParameterSpec = new GCMParameterSpec(GCM_TAG_LENGTH * 8, IV);

               // Initialize Cipher for ENCRYPT_MODE for encrypt plaintext
               cipher.init(Cipher.ENCRYPT_MODE, keySpec, gcmParameterSpec);

               // Perform Encryption
               byte[] cipherText = cipher.doFinal(plaintext);

               return cipherText;
           }

           public static String decrypt(byte[] cipherText, SecretKey key, byte[] IV) throws Exception
           {
               // Get Cipher Instance based on selective AES algorithm
               Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");

               // Create SecretKeySpec for key
               SecretKeySpec keySpec = new SecretKeySpec(key.getEncoded(), "AES");

               // Create GCMParameterSpec for key
               //IV = new byte[GCM_IV_LENGTH]; //here is issue

               GCMParameterSpec gcmParameterSpec = new GCMParameterSpec(GCM_TAG_LENGTH * 8, IV);

               // Initialize Cipher for DECRYPT_MODE to in plain text
               cipher.init(Cipher.DECRYPT_MODE, keySpec, gcmParameterSpec);

               // Perform Decryption on encrypted text
               byte[] decryptedText = cipher.doFinal(cipherText);

               return new String(decryptedText);
           }

       }

Output


Original Text : facing Issues on IT  (Learn from Others Experience)
Encrypted Text : AxboQXVKKPMm05cRaslMuxDl8IK77OLgG2ddnVSKzQUVQEXL/Xic+OHN/8ixbrFbvSrytStUWBsYQyXIWLQB22+0sg==
Exception in thread "main" javax.crypto.AEADBadTagException: Tag mismatch!
       at com.sun.crypto.provider.GaloisCounterMode.decryptFinal(GaloisCounterMode.java:524)
       at com.sun.crypto.provider.CipherCore.finalNoPadding(CipherCore.java:1023)
       at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:960)
       at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:824)
       at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:436)
       at javax.crypto.Cipher.doFinal(Cipher.java:2121)
       at enc_dec.AES_GCM_Example.decrypt(AES_GCM_Example.java:84)
       at enc_dec.AES_GCM_Example.main(AES_GCM_Example.java:41)

Solution

Here is an issue on decryption while changing the value of IV as in line by creating new byte array which is different from the value passed in encryption that’s why encryption and decryption authentication get failed.

As a solution specific this issue comment line 68 and it will return output as below.


Original Text : facing Issues on IT  (Learn from Others Experience)
Encrypted Text : faSkDrA737VyiocRk1n5arFGaO5r7GDN6xFmz7hjZppkN0y8sgcj9N5iqaZ2+gbRowli5Ocfm1sQB2qL+nEVIzsWVg==
DeCrypted Text : facing Issues on IT  (Learn from Others Experience)

References