If you want to prove that dependency injection is not a mystical cult, this tiny Spring Boot demo will do it. You will create a Spring Boot app, register a greeting bean, wire it with constructor injection, and watch embedded Tomcat shrug and start. Yes this is the classic Hello World, but with actual wiring and slightly fewer existential questions.
Use start.spring.io or your IDE project initializer to pick Spring Boot with the Spring Web dependency, or the minimal set you need for a console demo. A lean project saves build time and dependency drama. Add a main application class annotated with @SpringBootApplication
and a main method that calls SpringApplication.run
to start the context.
Define a class annotated with @Component
or @Service
that exposes a public method which prints a greeting. For learning you can use System.out.println
to see output on the console. For real apps prefer a logger for levels and better control in production.
Constructor injection is clearer and easier to test than field injection, so use that style. Inject the greeting bean into a CommandLineRunner
if you want the message to appear at startup, or inject it into a controller if you want the greeting to be served over HTTP. CommandLineRunner runs when the ApplicationContext finishes starting, which is perfect for a startup Hello World.
Start the app from your IDE or use your build tool to run it. If you included the web dependency embedded Tomcat will spin up and serve endpoints, and the console will show the println output or your logger message. If you see nothing check component scan packages and wiring choices. The usual suspects are wrong package locations or missing annotations.
This workflow produces a tiny but useful example of Spring Boot wiring that demonstrates inversion of control, Spring managed beans, and how a simple println helps validate wiring during the early learning phase. It is short, practical, and just sarcastic enough to keep you awake while you learn DI in Java with Spring Boot and embedded Tomcat.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.