How To Java.Lang.Noclassdeffounderror: Org/Springframework/Beans/Factory/Smartinitializingsingleton Inward Boundary Boot

Problem:
I was trying to run a HelloWorld programme using Spring Boot when I got this error:

Exception inwards thread "main" java.lang.IllegalStateException: Could non evaluate status on org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration#propertySourcesPlaceholderConfigurer due to internal cast non found. This tin give the sack hand if y'all are @ComponentScanning a springframework bundle (e.g. if y'all pose a @ComponentScan inwards the default bundle past times mistake)
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:52)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:92)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:174)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:136)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:116)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:324)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:117)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:689)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:969)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:958)
at boot.SpringBootDemo.main(SpringBootDemo.java:14)
Caused by: java.lang.NoClassDefFoundError: org/springframework/beans/factory/SmartInitializingSingleton
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at
org.springframework.boot.autoconfigure.condition.OnBeanCondition.collectBeanNamesForType(OnBeanCondition.java:164)
at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:153)
at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchingBeans(OnBeanCondition.java:121)
at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:95)
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:46)
... xvi more
Caused by: java.lang.ClassNotFoundException: org.springframework.beans.factory.SmartInitializingSingleton
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 33 more



I had the right starter dependency i.e. spring-boot-starter-web together with I was using @SpringBootApplication notation on my Main cast to run it within an embedded container.

I had created a Simple RESTful spider web service amongst a controller cast returning "Hello Spring Boot" equally shown below:

package boot;  import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;  @SpringBootApplication public class SpringBootDemo {    public static void main(String args[]) {     SpringApplication.run(SpringBootDemo.class, args);   }  }  @RestController class HelloControler {    @RequestMapping("/")   public String hello() {     return "Hello Spring Booot";   }  }

And my pom.xml (Maven dependency file looked similar below):

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">     <modelVersion>4.0.0</modelVersion>     <groupId>SpringMavenDemo</groupId>     <artifactId>SpringMavenDemo</artifactId>     <version>0.0.1-SNAPSHOT</version>     <name>MavenDemo</name>     <build>         <sourceDirectory>src</sourceDirectory>         <plugins>             <plugin>                 <artifactId>maven-compiler-plugin</artifactId>                 <version>3.1</version>                 <configuration>                     <source>1.7</source>                     <target>1.7</target>                 </configuration>             </plugin>         </plugins>     </build>     <dependencies>         <dependency>             <groupId>org.springframework.boot</groupId>             <artifactId>spring-boot-starter-web</artifactId>             <version>1.2.7.RELEASE</version>         </dependency>         <dependency>             <groupId>com.fasterxml.jackson.core</groupId>             <artifactId>jackson-databind</artifactId>             <version>2.2.3</version>         </dependency>         <dependency>             <groupId>org.springframework</groupId>             <artifactId>spring-web</artifactId>             <version>4.0.0.RELEASE</version>         </dependency>      </dependencies> </project>

There are 3 errors inwards this stack trace:

1. The Caused past times java.lang.ClassNotFoundException: org.springframework.beans.factory.SmartInitializingSingleton

2. The Caused by: java.lang.NoClassDefFoundError: org/springframework/beans/factory/SmartInitializingSingleton

3. Exception inwards thread "main" java.lang.IllegalStateException: Could non evaluate status on org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration#propertySourcesPlaceholderConfigurer due to internal cast non found.

This tin give the sack hand if y'all are @ComponentScanning a saltation framework bundle (e.g. if y'all pose a @ComponentScan inwards the default bundle past times mistake)


Solution:

The argue was next conflicting dependencies whihc I conduct maintain already had inwards my project, just inwards the pom.xml.
<dependency>     <groupId>com.fasterxml.jackson.core</groupId>     <artifactId>jackson-databind</artifactId>     <version>2.2.3</version> </dependency> <dependency>     <groupId>org.springframework</groupId>     <artifactId>spring-web</artifactId>     <version>4.0.0.RELEASE</version> </dependency>

 Main argue was incompatible version of Spring library inwards the classpath. Earlier I had used spring-web 4.0.0 free but Spring Boot 1.2.7 spider web starter ask higher version of library. The cast which was inwards query i.e. SmartInitializingSingleton wasn't acquaint inwards before version of library.

After I take those maven dependencies, my projection only ran fine. There was no error inwards the log file together with I tin give the sack run across the Spring Boot printed inwards the log file. As shown inwards next screenshot:

propertySourcesPlaceholderConfigurer due to internal cast non constitute How to java.lang.NoClassDefFoundError: org/springframework/beans/factory/SmartInitializingSingleton inwards Spring Boot



That's all almost how to cook "java.lang.NoClassDefFoundError: org/springframework/beans/factory/SmartInitializingSingleton" error inwards Spring Boot. As amongst whatsoever other ClassNotFoundException or NoClassDefFoundError, this was likewise related to loading incorrect cast from the classpath. Just endure careful non to mix private dependency amongst Spring kick starter dependency unless y'all certain that the explicit dependency is complete, non acquaint equally business office of starter dependency.

Further Learning
Spring Framework 5: Beginner to Guru
Master Microservices amongst Spring Boot together with Spring Cloud 
Official Spring Boot Reference Guide

Thanks for reading this article together with then far. If y'all are facing the same occupation together with if this article helped y'all to solve your occupation delight part amongst your friends together with colleagues. 

0 Response to "How To Java.Lang.Noclassdeffounderror: Org/Springframework/Beans/Factory/Smartinitializingsingleton Inward Boundary Boot"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel