Error: BeanDefinitionStoreException failed to read candidate component class

Following are some of the things that you can check:

Cause 1: Compatibility between Java and Spring

In this program, the use of Spring 3 has been done but Java 8 is compatible with Spring framework 4.0. The spring framework 4.0 have something known as functional interfaces which are compatible with Java 8. The use of Spring 3 was the cause of this problem.

Solution:

The only solution to this problem is by upgrading our Spring version to 4.x because Spring 3.x is only compatible till the Java 7 only. It doesn’t support the format of Java 8, i.e., bytecode format. Java 8 supports method references and lambda expressions rather than the Spring callback interfaces. Therefore, spring 3.x has to be updated to a newer version.

Cause 2: Context initialization

There is an error also called class path error. The error is of context initialization. The class path annotations have not been established.

Solution:

The solution to this problem is also upgrading the Spring 3.x to Spring 4.x. This is the most effective solution to remove the context initialization error. There are some upgrades of spring which should be followed in the program because of the upgradations in the bytecode in Java 8.

Cause 3:  FileNotFoundException

Solution:

In case, class file is not found of which an entry is present in the spring.xml (descriptor file?), it throws a FileNotFoundException which doesn’t let it compile further. Remember, the class file is being referred everytime an object is handling a segment of your code as it matches the objects linked to it.

EXAMPLE

Cause 4:  Exception thrown when a BeanFactory encounters an invalid bean definition

Solution:

Check your spring-servlet.xml carefully and make sure your property tag including name and value are rightly placed in their right positions along with the right order.

EXAMPLE

 

After the above two processes, check all the dot property files such as jdbc.properties and enter the correct path for loading the database driver class like this: jdbc.driverClassName=com.mysql.jdbc.Driver;

Jdbc.properties file.

Lastly, upgrade your spring to spring 4 because Java 8 doesn’t support Spring 3.

Cause 5: Spring Dependency Conflicts in the POM file

The spring dependencies in the file could get harder to resolve. When you have written a whole page of code and then when you compile the project, you are encountering errors such as NullPointerException or NoThreadException, then your first attempt is changing directories. You find out that the spring library you are using has two versions of it. This is due to the spring dependency conflicts in the file.

Solution:

Suppose there is a library X and there are two libraries Y and Z that are inside X. Both Y and Z have different versions of the library G (1.0 and 2.0 respectively). This may cause conflict dependencies.

The solution to this problem can be installing the Z library before the library Y. Yet another alternative is installing the library Z inside the POM file of X thus creating a direct functional dependency of X to Z.

We should make sure that a single version is used to create all the dependencies. This could cater the problem of the dependency conflicts.

Here Spring asm is in dependency conflict to Spring core. Therefore, when we make a Dependency Hierarchy, we have to cut all the dependencies linking to the asm file.

Leave a Reply