16 To 18
16 To 18
// Simple POJO (Plain Old Java Object) class Greeting { private String message; public
Greeting(String message) { this.message = message;
}
public String getMessage() { return message;
}
}
// Spring Component
@Component
class GreetingService { public Greeting getGreeting() { return new Greeting("Hello,
Spring!");
}
}
public Long getId() { return id; } public void setId(Long id) { this.id = id; }
public String getTitle() { return title; } public void setTitle(String title) { this.title = title;
}
@GetMapping("/")
public String home() { return "Hello, Spring Boot Web!";
}
}
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" ...>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>helloweb</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.0</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
How to Run
Place the Java file in:
src/main/java/com/example/helloweb/HelloWebApplication.java
Use this command:
bash CopyEdit mvn spring-boot:run
Output :
After running, visit:
arduino CopyEdit http://localhost:8080/
✅ output
Hello, Spring Boot Web!