- Annotate class with
@Configuration
@Import
thePrinterConfig
- Let IntelliJ do the work for you
- Open StringPrinter interface
- Place the text cursor on the interface name in file
- Alt + Enter -> Select "Implement Interface"
- Name it
- Annotate class with
@Configuration
- Create a
@Bean
that returns your implementation ofStringPrinter
- Make sure your method return type is
StringPrinter
- Make sure your method return type is
- Annotate class with
@Component
- Create a constructor that takes in
StringPrinter stringPrinter
as a parameter - Add
@Autowire
to the constructor - Call
stringPrinter.print()
in the constructor - Open MainConfig, add
@ComponentScan(basePackages = {"com.example"})
so your@Component
is seen by Spring
- Open
SpringApplicationRunner
- Instantiate a new
SpringApplication
, passing inMainConfig.class
- Call
.setWebEnvironment(false)
on the object- This isn't a web project, but Spring Boot defaults to thinking it is
- Call
.run()