Command-line Java application with Spring 4

How does a Spring 4 command-line Java application may look like? On this blog, we will look into the simplest Java application that uses @Configuration and AnnotationConfigApplicationContext. With sample codes, we’ll look into how to add .properties file to you application context.

Using @Configuration

@Configuration is a new way to configure you application. It is a class-level annotation.

The Main Class

In this example, our application context is represented by AnnotationConfigApplicationContext. To use your @Configuration file, register it with AnnotationConfigApplicationContext via the register method.

If you’d like, you may reference .properties files using AnnotationConfigApplicationContext.

Download the Maven Project

You may download the files here https://www.dropbox.com/s/nqs2ph3fpo9fj2t/com-turreta-cli-java-spring4.zip?dl=0

Karl San Gabriel

Karl San Gabriel

Java and Enterprise Technologies Expert