It's never too late to learn something new
I started learning spring boot and ran into several complications due to overlooking some tiny details that result in major issues in the application you're working on.
1.Creating a package which is not included in parent package
In the below image controller package is created out of parent package i.e.,com.example.demo which has main method
which gives this error as below
Moved child package to its parent package and child package became com.example.demo.controller
Now getting the response
2.Missing stereotype annotations
Some of stereotype annotations are:
@Component -used to denote a class as a Component which marks beans as spring managed components
@Service - to indicate that they’re holding the business logic
@Repository - to indicate that they’re dealing with CRUD operations
@Controller - to indicate that they’re front controllers and responsible to handle user requests and return the appropriate response
Missed one of the stereotype annotation i.e.,@Service in below image that lead to application fail to start
3.Missing Auto wiring and expecting Result
Missing @Autowired won't give any error or problem to start the application as seen below there is not autowiring for ServiceImp class and using trying to use it getData() method's return statement
But when the request call happened gives following error and throws Null pointer Exception. So never miss Autowiring if you are seeking a serivce or a repository in your method call
4.Spelling Mistakes
Many times I do this a lot and expect results,I know its a silly thing to talk about but still it brings lot of difference .Fortunately now I am getting used to my mistakes and trying to avoid them as much as possible.
If you are using some IDE's like STS,eclipse you will be notified mostly about mistake you are making, what if you are making spelling mistakes in database connection file i.e., in application.properties file .
For example if password is root and you typed it as roet, particularly i did this and worrying why my database is not getting connected with.
Corrected the spelling and it worked
5.Missing required Dependencies
Another common mistake which has lot of scope for many i.e., missing requried dependecies like spring web which throws following exception