DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Jakarta NoSQL: Why JPA Is Not Enough for the AI Era
  • Top Java Security Vulnerabilities and How to Prevent Them in Modern Java
  • A Spring Boot App With Half the Startup Time
  • Implementing the Planning Pattern With Java Enterprise and LangChain4j

Trending

  • The New Insider Threat Isn't Human: Securing AI Agents Before They Secure Themselves
  • Your Biggest Identity Problem Isn't Your Employees Anymore; It's Everything Else
  • I Built a VS Code Extension to Debug Azure AI Foundry Agents Without Leaving My Editor
  • Data Governance Checklist for AI-Driven Systems
  1. DZone
  2. Coding
  3. Java
  4. Spring(boot)ing to the Web With Java and Pom.xml

Spring(boot)ing to the Web With Java and Pom.xml

Following along as one developer shows you how to set up an app with Spring Boot using some Java and a single Pom.xml file.

By 
Ajitesh Kumar user avatar
Ajitesh Kumar
·
Sep. 23, 16 · Tutorial
Likes (17)
Comment
Save
Tweet
Share
15.0K Views

Join the DZone community and get the full member experience.

Join For Free

This blog presents instructions on how to quickly get started with Spring Boot Hello World with just one Java file and a Pom.xml.

Image title

Before getting to the files, make sure you have installed and configured the following:

  • Java: Set up Java_Home, as it is required by Maven.
  • Maven: Maven would be used to package our app.

Java Code Sample

Below is the code for the Java file. Make sure to create hello/HelloController.java file within src/main/java. This is required for Maven to package it correctly.

package hello;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

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

@RestController
@SpringBootApplication
public class HelloController {

    @RequestMapping("/")
    String home() {
        return "Hello World!";
    }

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

}

 

Pom.xml Code Sample

The following is the code for the Pom.xml file. Make sure to put Pom.xml at the topmost level (alongside the src folder):

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>hello</groupId>
    <artifactId>SpringBootSampleWeb</artifactId>
    <version>0.0.1</version>
<properties>
    <!-- The main class to start by executing java -jar -->
    <start-class>hello.HelloController</start-class>
</properties>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.0.RELEASE</version>
    </parent>

    <!-- Additional lines to be added here... -->
    <dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
</project>


Package and Run the App

Once you have created the file, execute the following command to run the code:

mvn package 
java -jar target/SpringBootSampleWeb-0.0.1.jar 
Java (programming language)

Published at DZone with permission of Ajitesh Kumar. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Jakarta NoSQL: Why JPA Is Not Enough for the AI Era
  • Top Java Security Vulnerabilities and How to Prevent Them in Modern Java
  • A Spring Boot App With Half the Startup Time
  • Implementing the Planning Pattern With Java Enterprise and LangChain4j

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook