I'm just starting off with Spring , I have created a basic Spring boot web app with - Thymeleaf templates, JPA and Mysql.
When I use the autowiring and annotate all the classes everything works. Here is an example of the working code.
Simple product class with the @Component annotation

Simple DAO class with the @service annotation

Basic controller with the @Autowired annotation to get DAO instance

So when I call the get method , I'm able to see a list of products: 2 products displayed

Now when I transition to the java configuration , this stops working. I commented out the annotations and added a new java config file.
the @Autowiring annotation also removed from the Controller
Added a java class with the @Configuration, see config file:

Just to make sure the context loaded the beans, I took the configurable context that was returned by the run method and checked if the bean was loaded.
Get the DAO bean and call the method to get the Product line items

This also works as I could see the object was not null. Also I could get a count of the products in the output immediately after the application was started.
Everything is ok till here and the application has started. But now when I access the URL - I get an error
Summary This example is only being done to understand Spring and is not following proper DDD practices.
Here is a summary of the steps, the issues are in step 4(b)
- DAO creates 2 Product instances, puts into a list and returns it.
- The DAO is injected into the controller. The controller calls the getproducts() on the DAO and returns the list of products.
- Everything works with the component and service Annotations combined with @Autowiring
- Problem comes when I use a Java configuration. (a) After application startup I get the context and verify if the beans are loaded. (I'm doing this in the main application.) (b) Only when I hit the url and when the controller tries to call the method on the DAO I get the problem.