import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; // A simple dependency class @Component public class Dependency { public void performAction() { System.out.println("Action performed by Dependency"); } } // Service class using @Autowired for dependency injection @Component public class MyService { private final Dependency dependency; // Constructor injection using @Autowired @Autowired public MyService(Dependency dependency) { this.dependency = dependency; } public void doSomething() { // Using the injected dependency dependency.performAction(); } } // Main application class import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ConfigurableApplicationContext; @SpringBootApplication public class MyApp { public static void main(String[] args) { ConfigurableApplicationContext context = SpringApplication.run(MyApp.class, args); // Retrieving the MyService bean from the Spring context MyService myService = context.getBean(MyService.class); // Using the MyService bean myService.doSomething(); // Closing the Spring context context.close(); } }