As a spring boot beginner, there are a few common blunders to avoid.

As a spring boot beginner, there are a few common blunders to avoid.

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

Screenshot (90)_LI.jpg which gives this error as below

Screenshot (91).png

Moved child package to its parent package and child package became com.example.demo.controller

Screenshot (92).png

Now getting the response

Screenshot (93).png

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

Screenshot (90).png

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

Screenshot (97).png

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

Screenshot (98).png

Screenshot (99).png

4.Spelling Mistakes

  1. 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.

  2. 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 .

  3. 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.

Screenshot (101).png

Corrected the spelling and it worked

Screenshot (100).png

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

Screenshot (102).png

Did you find this article valuable?

Support Vinay Rangaraju by becoming a sponsor. Any amount is appreciated!