Java Spring, a popular open-source framework, simplifies enterprise-level application development on the Java platform. Let's dive into a code example to understand its basic concepts and syntax.

Spring provides a comprehensive infrastructure supporting rapid Java application development and enterprise integration. It follows the Inversion of Control (IoC) principle, managing the complexity of object lifecycles.

Setting Up a Simple Spring Boot Project
To start with, let's set up a simple Spring Boot project using the Spring Initializr tool (start.spring.io). Choose "Web" as a dependency, and download the project as a ZIP file.

Unzip the file and import it into your preferred Integrated Development Environment (IDE) such as IntelliJ IDEA or Eclipse.
Hello World with Spring Boot

In the generated project, navigate to the com.example.demo package and create a new class named HelloWorldController. This will be our Spring Boot controller, handling HTTP requests.
Implement the HelloWorldController class with the following code:
```java import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloWorldController { @GetMapping("/hello") public String helloWorld() { return "Hello, Spring Boot!"; } } ```
The @RestController annotation indicates that this class handles HTTP requests, and @GetMapping("/hello") maps the HTTP GET request to the helloWorld() method. When accessed, this method returns "Hello, Spring Boot!".

Running the Application
To run the application, right-click on the main class (DemoApplication) in your IDE and select "Run 'DemoApplication' main class". The Spring Boot server will start on http://localhost:8080.
Access http://localhost:8080/hello in your web browser, and you should see "Hello, Spring Boot!" displayed in the response.

Dependency Injection with Spring
Spring uses IoC to manage dependencies between objects. It does this by injecting the required dependencies into objects when they're created.









Let's create a service class and demonstrate dependency injection.
Creating a Service Class
In the com.example.demo package, create a new class named HelloWorldService. Implement the class with the following code:
```java public class HelloWorldService { public String getGreeting() { return "Hello, World!"; } } ```
The HelloWorldService class has a single method, getGreeting(), which returns a greeting message.
Injecting the Service into the Controller
Modify the HelloWorldController class to inject the HelloWorldService and use its method:
```java import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloWorldController { private HelloWorldService service; @Autowired public HelloWorldController(HelloWorldService service) { this.service = service; } @GetMapping("/hello-injected") public String helloWorldInjected() { return service.getGreeting(); } } ```
The @Autowired annotation tells Spring to inject an instance of HelloWorldService into the controller. The helloWorldInjected() method now uses the injected service to return the greeting message.
Start the application again, and access http://localhost:8080/hello-injected. You should see the message "Hello, World!" displayed in the response. This demonstrates how Spring injects dependencies into objects.
As the application evolves, dependency injection helps manage complexity and promotes high Cohesion and low Coupling, two fundamental principles of software design.
Spring Boot makes it easy to create production-grade applications quickly. By understanding the basic principles of IoC and dependency injection, you're well on your way to becoming a proficient Spring developer. Happy coding!