Spring

1. Inversion of Control /Dependency Injection :  As a developer you configure the dependencies and container takes care of instantiating and injecting those at runtime. So container is doing your work.  By doing so, you are avoiding lots of boilerplate code.

In IoC paradigm, rather than your custom code calling the framework code ( libraries ) , the framework is calling your custom code ( dependencies ).

org.springframework.context.ApplicationContext represents the Spring IOC container. ClassPathXmlApplicationContext or FileSystemXmlApplicationContext  are implementations of this interface. 

2. To generate starter code for any Spring project you can use following site

https://start.spring.io/


3.  Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity

This happens for a couple of reasons.
1. Missing @Id annotation for an Entity.
2. Wrong imported class for Id.

For example  having

import org.springframework.data.annotation.Id;

        in place of

import javax.persistence.Id;

4.   Error from Repository :   <EntityName>   not mapped.

In Repository you specify "FROM   EntityName" . The  EntityName  should not be the actual table name from where you are querying but rather the Entity class name  which is pointing to that table.


5. Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test

This was happening because , spring boot looks for a class with @SpringBootApplication annotation in the package tree structure , starting from where the current test class is  and going up the hierarchy.   Because I had a type in the package declaration for the test class, so it did not find the SprintBootApplication  and hence above error. 


References:

https://www.baeldung.com/inversion-control-and-dependency-injection-in-spring
https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#spring-core
https://dzone.com/articles/what-is-spring-boot

Comments

Popular posts from this blog

SQL

Analytics

HIVE