This project demonstrates field injection: Spring supplies a Data implementation to FetchData, and the app calls that implementation to print a result.
pom.xml— Maven configuration for the Spring Boot project and Java 17.SpringBootDependencyDataFetchProjectApplication.java— starts Spring Boot, retrievesFetchData, and callsshow().Data.java— interface defining thegetData()operation.Oracle.java—Dataimplementation marked@Primary; printsFetching data from oracle.MYSQL.java— alternateDataimplementation; printsfetch data from sql.FetchData.java— uses@Autowired private Data d;and callsd.getData()insideshow().
Both Oracle and MYSQL implement Data. When Spring injects a Data bean into FetchData, @Primary marks Oracle as the default choice. That is why the app prints the Oracle message.
In the Paradise project, Billcounter.java uses constructor injection through Billcounter(PaymentMode p). In this project, FetchData.java uses field injection through @Autowired on Data d.
Fetching data from oracle
get the data
