Spring Boot Hello world StandAlone application

In this post, we are going to create Spring Boot Hello world StandAlone application. We have already created Spring boot web hello world example.

It is very easy to configure Spring standalone project using Spring boot.

Github Source code:


Project Structure:

Spring Boot standalone project structure


Step 1:  Create a simple java  project using maven in eclipse named "SpringBootHelloWorldStandaloneExample".
Step 2: Change "pom.xml" as below:

Step 3: Create a file named "Country.java" in package .org.arpit.java2blog.springboot

If you notice, we are using @Value("{countryName}") for countryName attribute.Actually, this syntax is used to read a String from the property file. In the next step, we will put "countryName=India" in application.properties. We have declared this bean with @Component annotation, so spring boot will automatically find this bean using component scan.
Step 4: Create a file named "application.properties" in package src/main/resources

Step 5: Create a file named "SpringBootHelloWorldStandaloneApplication.java" in package .org.arpit.java2blog

You can read more about @Autowire and @Qualifier.

The SpringBootHelloWorldStandaloneApplication’s main method uses Spring Boot’s pringApplication.run() method to launch a spring application.If you notice, we did not do any single line of xml configuration here.

We have implemented CommandLineRunner interface here. This interface indicates that bean should run if it is contained in spring application.
When you run above application, you will get below output.

2017-05-06 00:12:49.911 INFO 15824 — [ main] pringBootHelloWorldStandaloneApplication : Starting SpringBootHelloWorldStandaloneApplication on apples-MacBook-Air.local with PID 15824 (/Users/apple/Documents/WorkspaceAlgo/SpringBootHelloWorldStandaloneExample/target/classes started by apple in /Users/apple/Documents/WorkspaceAlgo/SpringBootHelloWorldStandaloneExample)
2017-05-06 00:12:49.914 INFO 15824 — [ main] pringBootHelloWorldStandaloneApplication : No active profile set, falling back to default profiles: default
2017-05-06 00:12:50.012 INFO 15824 — [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.spring[email protected]5579bb86: startup date [Sat May 06 00:12:50 IST 2017]; root of context hierarchy
2017-05-06 00:12:50.817 INFO 15824 — [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
Country Name: India
2017-05-06 00:12:50.838 INFO 15824 — [ main] pringBootHelloWorldStandaloneApplication : Started SpringBootHelloWorldStandaloneApplication in 1.421 seconds (JVM running for 2.006)
2017-05-06 00:12:50.839 INFO 15824 — [ Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.spring[email protected]5579bb86: startup date [Sat May 06 00:12:50 IST 2017]; root of context hierarchy
2017-05-06 00:12:50.841 INFO 15824 — [ Thread-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown

That’s all about Spring Boot Hello world StandAlone application.

Was this post helpful?


You may also like:

Related Posts

  • 11 January

    Spring boot JDBC example

    Table of ContentsTools usedProject StructureCreate new Spring boot projectMaven configurationConfigure datasource in Application.propertiesCreate database tableCreate model classCreate Repository interface and implementationCreate service interface and implementationCreate Application classRun the applicationVerify database outputGithub Source code In this post, we will see Spring boot JDBC example. As we already know Spring boot does lot of auto configurations which […]

  • 02 January

    Spring boot devtools tutorial

    Table of ContentsOverviewJRebelIntroduction to Spring Boot DevToolsAdding Devtools to your projectSpring Boot DevTools FeaturesProperty DefaultsLoggingCachingAutomatic RestartLive ReloadGlobal SettingsRemote ApplicationsFile System WatchersConclusion In this post, we’ll be looking up what does spring has to offer for developer experience. Overview Using IDEs like Eclipse, Spring Tool Suite, Intellij Idea a typical development setup includes an application code […]

  • 26 December

    Spring boot H2 Database example

    Table of ContentsWhat is H2 database?Tools usedGithub Source code:Project StructureCreate new Spring boot projectMaven configurationH2 database configurationOverride H2 databse defaultsModelRepositoryServiceControllerSpring boot main fileRun the applicationTest the applicationCreate movie objectGet all movie objectsDelete movie id 3 In this post, we are going to see how to create Spring boot application integrating with H2 database. What is […]

  • 22 December

    Spring Boot CrudRepository

    Table of ContentsTools usedProject Structure:Wiring up MongoDBThe Repository ClassThe Save methodThe User Entity ClassBringing the UserDao and CrudRepository togetherServiceControllerApplication classRunning the code sampleConclusionSource code In this post, we’ll be looking up how to create and use Spring Boot CrudRepository. SpringBoot CrudRepository provides sophisticated CRUD functionality for the type of entity you want to be managed.This […]

  • 10 April

    Difference between Spring and Spring boot

    Table of ContentsSpring frameworkSpring bootAdvantages of Spring BootSpring vs Spring boot In this post, we will see difference between Spring and Spring boot. If you have followed spring project over time, you might have noticed it has become increasingly complex. If you want to create a spring application, you still need to put a lot […]

  • 17 September

    Spring Boot SOAP Web service Example

    Table of ContentsTools usedProject structureAdd wsdl4j dependencyXSD file to define domainGenerate domain classes based on XSDCreate Book repository with dummy dataDefine Book service endpointDefine web service configurationRun the applicatonTest WSDL URLTest Spring soap web serviceSource code In this post, we will see how to create soap web services with Spring boot. We will create contract […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.