Showing posts with label spring framework. Show all posts
Showing posts with label spring framework. Show all posts

Wednesday, December 11, 2019

Java.Lang.Classnotfoundexception: Org.Springframework.Web.Context.Contextloaderlistener [Solution]

Problem : You are getting java.lang.ClassNotFoundException : org.Springframework.Web.
Context.ContextLoaderListener inward your Spring-based Java Web application.
Cause: This fault comes when you lot are using Spring MVC framework inward your Java Web application as well as configured org.springframework.web.context.ContextLoaderListener equally a listener inward your deployment descriptor equally good known equally web.xml, but the JAR which contains this degree is non available inward spider web application's CLASSPATH.


This is a really of import degree inward Spring MVC framework, equally it is used to charge your boundary configuration files e.g. applicatoin-Context.xml as well as others, defined inward the context-param chemical portion of web.xml of your Java boundary spider web application, equally shown below :
    <context-param>         <param-name>contextConfigLocation</param-name>         <param-value>classpath:application-Context.xml</param-value>     </context-param>      <listener>         <listener-class>             org.springframework.web.context.ContextLoaderListener         </listener-class>     </listener> 



Approach : Like whatsoever other ClassNotFoundException error, you lot offset demand to abide by out the JAR file on which this degree is bundled as well as and thus add together that JAR into the appropriate place, e.g. WEB-INF/lib folder of your spider web application. So that the spider web application degree loader e.g. org.apache.catalina.loader.WebappClassLoader tin forcefulness out come across this JAR file. You tin forcefulness out come across inward below stack describe that it's the WebappClassLoader which failed to charge this degree :
SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)     at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)     at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)     at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)     at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4660)     at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)     at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)     at java.util.concurrent.FutureTask.run(FutureTask.java:138)     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)     at java.lang.Thread.run(Thread.java:662)


Solution :  It appears that the boundary context loader listener degree i.e. org.springframework.web.context.ContextLoaderListener  is moved to spring-web.jar since Spring 3.0. which way you lot should create next to fix java.lang.ClassNotFoundException : org.Springframework.Web.Context.ContextLoaderListener fault :


1. If you lot are using Spring version 3.0 as well as thus add together spring-web.jar into CLASSPATH i.e. exactly pose it within WEB-INF/lib folder.

2. If you lot are running inward Spring 2.0 or lower version as well as thus exactly add together spring.jar into your application's CLASSPATH, same exactly pose it within WEB-INF/lib directory.

3. If spring.jar or spring-web.jar is already inward CLASSPATH as well as thus your work is non due to JAR but due to wrongly configured classpath. See my ship service how to bargain alongside ClassNotFoundException to troubleshoot  further.

4. If you lot are using Maven the add together next dependency inward your pom.xml file :
         <dependency>             <groupId>org.springframework</groupId>             <artifactId>spring-web</artifactId>             <version>3.2.6.RELEASE</version>         </dependency> 


5. If you lot are getting java.lang.ClassNotFoundException : org.Springframework.Web.Context.ContextLoaderListener error In Eclipse as well as Tomcat, as well as thus you lot tin forcefulness out equally good effort next steps to brand certain maven dependencies are inward CLASSPATH as well as visible to Tomcat's spider web application degree loader. All you lot demand to create is add together maven dependencies into your eclipse project's spider web deployment assembly.
  • Select Project, Right click as well as select Properties.
  • Choose "Deployment Assembly".
  • Click the "Add..." push on the correct side.
  • Choose "Java Build Path Entries" from the carte du jour of directive type as well as click "Next".
  • Select "Maven Dependencies" from the Java Build Path Entries carte du jour as well as click "Finish".
You volition come across maven dependencies added to the spider web deployment assembly Definition past times now.

6. If  you are getting java.lang.ClassNotFoundException : org.Springframework.Web.Context.ContextLoaderListener error in previously working projection as well as you lot are certain that you lot non done anything which causes this fault as well as thus you lot tin forcefulness out try "Clean Tomcat Work Directory" or only "Clean..". This is supposed to discard all published country as well as republish from scratch.

Spring MVC books as well as resources
Spring Web Application Developer Certification

Thanks for reading this article thus far. If you lot similar this interview enquiry as well as thus delight percentage alongside your friends as well as colleagues. If you lot accept whatsoever enquiry or proposition as well as thus delight drib a comment as well as I'll effort to abide by an response for you.

Other mutual ClassNotFoundExceptions which comes inward Java programs :
  • General Guide to solve java.lang.ClassNotFoundException inward Java [guide]
  • How to solve java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver inward Java? [solution]
  • How to solve java.lang.ClassNotFoundException:org.Springframework.Web.Context.ContextLoaderListener [solution]
  • How to solve java.lang.ClassNotFoundException: com.mysql.jdbc.Driver inward Java MySQL? [solution]
  • java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory? [solution]
  • How to connect to MySQL database from Java Program [steps]
  • How to fix java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver inward Java? [solution]
  • How to ready java.lang.ClassNotFoundException: org.postgresql.Driver fault inward Java? [solution]

P.S. - If you lot desire to larn how to educate RESTful Web Services using Spring Framework, cheque out Eugen Paraschiv's REST alongside Spring course. He has lately launched the certification version of the course, which is amount of exercises as well as examples to farther cement the existent globe concepts you lot volition larn from the course.

Saturday, November 9, 2019

How To Forestall Browsers From Caching Static Contents Using Jump Mvc Framework

One of the mutual requirement inwards a secure Java spider web application is to disallow dorsum push of browser or invalid the session if the user hitting the dorsum push of the browser. You mightiness lead keep seen this behaviour spell doing online banking or cyberspace banking, almost all the banks don't allow y'all to purpose the browser's dorsum button. Your session gets terminated equally shortly equally y'all hitting the dorsum push together with y'all lead keep to log inwards i time again to produce whatsoever transaction. Btw, Have y'all e'er checked about province of affairs on your Java spider web application like, if y'all pressed the dorsum push of your browser later logging in, what happened? You volition honour that browser takes y'all to the previous page. This happens because your browser normally doesn't ship about other GET request to the server. Instead, it views the spider web page from locally cached responses. This is called browser caching/HTTP caching, it could laissez passer on non alone on a login page but on whatsoever page. This behaviour is genuinely controlled past times the Cache-Control header of HTTP response.

Ideally y'all spider web application should redirect y'all to your after-logged-in-page (usually the Homepage) instead of showing the login cast page or precisely just invalidate the session if safety doesn't permit that. Anyway, inwards this article, I'll order y'all how y'all tin instruct the browser to non cache the dynamic content inwards its local cache past times using the cache-control header.

If y'all are developing your Java Web application using Spring MVC framework (if y'all are not, therefore y'all should) provides an tardily way to halt dynamic content caching at Browser.You require to declare a WebContentInterceptor edible bean together with define its properties inwards your servlet context file to preclude browsers from caching dynamic content.


The WebContentInterceptor is a Handler Interceptor inwards Spring MVC framework that checks the asking together with prepares the response. It checks for supported methods together with a required session together with applies the specified CacheControl builder. This interceptor is mainly intended for applying checks together with preparations to a laid of controllers mapped past times a HandlerMapping.

Here is a sample configuration y'all tin purpose to preclude browsers from caching dynamic content e.g. content generated past times Servlet, JSP, or whatsoever other dynamic technology:

<!--Prevent browsers from caching contents except for the static resources content-->     <mvc:interceptors>         <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"               p:paramName="lang"/>         <mvc:interceptor>             <mvc:mapping path="/**"/>             <mvc:exclude-mapping path="/resources/**"/>             <bean id="webContentInterceptor"                    class="org.springframework.web.servlet.mvc.WebContentInterceptor">                 <property name="cacheSeconds" value="0"/>                 <property name="useExpiresHeader" value="true"/>                 <property name="useCacheControlHeader" value="true"/>                 <property name="useCacheControlNoStore" value="true"/>             </bean>         </mvc:interceptor>     </mvc:interceptors>

This configuration volition intercept all asking because mapping path is a wildcard which volition fit all asking path, but therefore all the asking which has /resources inwards the URL volition last excluded. This agency y'all require to seat your static resources e.g. HTML, JavaScript, images into that path.


That's all close how to disable local content caching using Spring framework. This is an of import characteristic from a safety indicate of sentiment which Spring MVC framework provides out-of-the-box. You tin likewise command together with customize the behaviour past times setting the value which your application needs e.g. y'all tin specify the seat out of seconds earlier cache expires.  If y'all desire to larn to a greater extent than close safety inwards a spider web application, I propose y'all bring together Learn Spring Security Masterclass past times Eugen Paraschiv of Baeldung.

Further Reading
Spring Framework 5: Beginner to Guru
Spring Master Class - Beginner to Expert
How Spring MVC framework Works Internally
How to enable Spring Security inwards Java Web Application
How to transcend Spring Web Application Developer Certification
23 Spring MVC Interview Questions together with Answers
Spring together with Hibernate for Beginners

Thanks for reading this article, if y'all similar this article, therefore delight percentage amongst your friends together with colleagues. If y'all lead keep whatsoever query or feedback therefore delight driblet a comment together with I'll endeavor to honour an respond for you.

P.S. - If y'all desire to larn how to educate RESTful Web Service using Spring MVC inwards depth, I propose y'all bring together the REST amongst Spring certification class past times Eugen Paraschiv. One of the best course of report to larn REST amongst Spring MVC.

Solving Org.Springframework.Beans.Factory.Beancreationexception: Mistake Creating Edible Bean Alongside Lift Ten [Java Spring]

If yous are using Spring framework inwards your Java application too getting this mistake during startup it agency Spring is non able to initialize the edible bean X too add together into its application context, Why? There could move multiple reasons e.g. a typo on jump edible bean name. Let's receive got a closer seem at the stack describe to honor out the existent reason:

BeanInstantiationException: Could non instantiate edible bean cast [X]: No default constructor found; nested exception is java.lang.NoSuchMethodException: X.()

Here X is the class, which is declared every bit Spring bean. The mistake clearly says that default constructor is non acquaint inwards cast X. By default, Spring volition show to instantiate beans past times calling the default or no-argument constructor too if it doesn't honor the default, no-argument constructor too so it is non able to initialize the edible bean too thence it throws the BeanInstantiationException during startup, the existent argue is too appended into stack describe every bit NoSuchMethodException.

If yous remember, Java past times default adds a default constructor inwards every cast but many programmers don't know that it solely does that if yous don't receive got whatsoever constructor inwards the cast if past times whatsoever conduct a opportunity yous receive got defined a constructor which takes a parameter, too so Java volition non add together it.

This is too 1 of the reasons I propose to always add together default constructor inwards Java class, no affair whether yous receive got to a greater extent than constructor or not. Java allows constructor overloading too yous should receive got payoff of that.

Now, it depends on how yous are instructing Spring to instantiate your bean? If yous are using auto-wiring e.g. @Autowired annotation, too yous too receive got a suitable constructor define too so merely annotated that alongside @Autwired annotation, every bit shown below:


public class X{ private D d;  @Autowired public X(Y dependency){ this.d = depenency; }  }

Your work volition move solved.

Btw, if yous are using XML based configuration too so brand certain yous are using correct constructor on your config.

Also, every bit per Spring Java documentation, Influenza A virus subtype H5N1 BeanCrationException is thrown when a BeanFactory encounters an mistake spell attempting to exercise a edible bean from edible bean definition. It doesn't state anything nearly the error, that's why yous bespeak to seem at the nested exception to honor the actual cause. For example, Like inwards this case, the nested mistake was BeanInstantiationException, which dot instantiation of a edible bean failed.



You should ever pay attending to detailed stack describe every bit It too carries the offending edible bean cast too argue e.g., inwards this case, it was trying to instantiate edible bean past times invoking default constructor too couldn't honor it. By looking at the error, yous tin conclude that whether yous bespeak to add together default constructor or Spring is invoking a incorrect constructor, which agency a missing config somehow.

Sometimes BeanInstantiationException is too throwing inwards Spring is non able to honor the edible bean cast inwards the classpath. That fourth dimension yous volition see either NoClassDefFoundError or ClassNotFoundException every bit nested exception inwards the stack trace.

solution)
  • java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet inwards Java Spring MVC Application [solution]
  • How to solve java.sql.BatchUpdateException: String or binary data would move truncated (guide)
  • How to solve java.lang.ClassNotFoundException: com.mysql.jdbc.Driver error? (hint)
  • 5 Reasons of NoClassDefFoundError inwards Java? (tutorial)
  • How to fix Caused By: java.lang.NoClassDefFoundError: org/apache/log4j/Logger (solution)
  • Cause of "java.lang.SecurityException: Missing required Permissions manifest attribute inwards master copy jar" [solution]
  • How to fix "illegal initiatory of all of expression" compile fourth dimension mistake inwards Java? (tutorial)
  • How to connect to MySQL database inwards Java? (tutorial)
  • How to cook "Error: Could non honor or charge master copy class" inwards Eclipse? (guide)
  • java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory mistake (solution)

  • java.sql.SQLException: No suitable driver found for 'jdbc:mysql://localhost:3306/mysql [Solution]

  • How to bargain alongside "No JVM installation found, delight install 64-bit JDK" error? (solution)
  • How to cook unable to honor certification path mistake inwards Java SSL? (guide)
  • How to avoid ConcurrentModificationException inwards Java? (tutorial)
  • How to solve "could not create the Java virtual machine" mistake inwards Java? (solution)
  • Common reasons of java.lang.ArrayIndexOutOfBoundsException inwards Java? (solution)
  • 10 mutual reasons of java.lang.NumberFormatException inwards Java? (tutorial)
  • java.sql.SQLServerException: The index 58 is out of arrive at - JDBC (solution)
  • Fixing java.lang.unsupportedclassversionerror unsupported major.minor version 50.0 (solution)
  • How to cook 'javac' is non recognized every bit an internal or external command (solution)
  • Cause too solution of "class, interface, or enum expected" compiler mistake inwards Java? (fix)
  • How to solve "variable mightiness non receive got initialized" compile fourth dimension mistake inwards Java? (answer)
  • How to solve java.lang.classnotfoundexception oracle.jdbc.driver.oracledriver? (solution)

  • Thanks for reading this article so far. If yous similar this troubleshooting guide too my explanation of Spring's BeanCreationException too so delight portion alongside your friends too colleagues. If yous receive got whatsoever enquiry or feedback, delight drib a comment.

    Top Five Jump Certification Written Report Guides For Core, Web, Together With Corporation Integration Exams

    Ever since Pivotal has announced that Spring preparation is non mandatory for becoming Pivotal certified Spring developer, to a greater extent than in addition to to a greater extent than experienced Java programmers, who own got been using Spring for years are preparing for the exam. This is obvious because the expensive Spring training, which toll approximately 32000 USD inward the USA in addition to most of the western nations in addition to approximately 50,000 INR inward Republic of Republic of India was the biggest hurdle on getting Spring certified. Even though preparation is the best agency to fix for certification because it is totally focused on certification examination in addition to y'all volition encompass all topics there, it is non affordable for most of the Java developers approximately the world. Now, the cost of Spring certification has merely reduced to 200 USD from the whopping 3200 USD it toll earlier.

    The motion to permit Java developers to appear inward Spring certification without mandatory preparation has too encouraged the pop self-study model which is quite pop because fifty-fifty traditional Oracle Java certifications are based upon that. It allows programmers to fix their ain footstep in addition to its too non really expensive.  All y'all demand is a study guide in addition to a Spring mock examination simulator.

    Even though y'all tin role Spring framework books to fix for certifications, but written report guide is specially important. The written report guide has many benefits over full general books e.g. they are focused on the certification exam. They fully encompass all topics in addition to own got topic-wise assessment questions.

    They too produce a proficient project on highlighting telephone commutation concepts from examination indicate of view. If y'all desire to produce good on Spring certification, it is must that y'all select a written report guide for your preparation. You tin too own got aid from Java Spring Framework four in addition to Spring Certification, a course of didactics from Udemy, especially designed for Spring certification in addition to currently they are offering 90% discount on that.





    Spring Certification Study guides

    Unfortunately, in that place are non many resources available to fix for Spring certifications because it is nonetheless non that pop equally compared to Oracle's Java certification. One argue for that was few developers opting for Spring certification due to expensive mandatory training.

    Now, that restriction is lifted y'all tin await to a greater extent than written report guides, books, in addition to mock examination volition come upward to aid Spring developer preparing past times themselves for Spring certifications.

    Btw, If y'all are an experienced Java developer and using Spring framework for a distich of years in addition to y'all mean value that y'all tin overstep Spring certification without much preparation, I propose y'all to rootage become through David Mayer's Online Spring Mock test, It's a gratis bear witness in addition to if y'all tin score over 80% in addition to thus y'all are cook for the existent exam.

    Anyway, hither are a distich of useful written report guides for Spring certification currently available inward the market. This listing includes written report guides for Spring core, Spring web, in addition to Spring Enterprise Integration certifications.



    Pivotal Certified Spring Web Application Developer Exam: Influenza A virus subtype H5N1 Study Guide 
    This is ane of the best books to fix for Spring Web application developer certification equally it non exclusively covers all topics but too teaches y'all essential concepts past times keeping the examination in addition to questions inward mind.

     for becoming Pivotal certified Spring developer Top five Spring Certification Study Guides for Core, Web, in addition to Enterprise Integration Exams




     RESTful services amongst Spring MVC, tasks in addition to scheduling, remoting, Spring spider web service, the Spring JMS module, JMS in addition to JTA transactions amongst Spring, batch processing amongst Spring Batch in addition to the Spring Integration framework.

     for becoming Pivotal certified Spring developer Top five Spring Certification Study Guides for Core, Web, in addition to Enterprise Integration Exams



    Pivotal Certified Spring Professional Certification Exam: Influenza A virus subtype H5N1 Study Guide 
    This is a proper written report guide for Spring amount certification. It covers all topics in addition to essential concepts. It too has topic wise questions for Spring certification to fix well. One book, which y'all tin combine amongst Spring inward Action to fix actually good for the exam.

     for becoming Pivotal certified Spring developer Top five Spring Certification Study Guides for Core, Web, in addition to Enterprise Integration Exams


    Official Spring Core Study Guide
    This is some other gratis written report guide from Pivotal which contains some must know information close Spring certification in addition to topic wise questions to cheque your understanding. It merely contains questions without whatever answer, but questions are proficient in addition to y'all tin too role them for preparing Spring interviews.

    If y'all are using Spring for a distich of years in addition to thus y'all already know answers to most of them. They are too proficient to speedily cheque if y'all are cook for Spring certification or non because passing percent is quite high for Spring certification. You demand to acquire 38 out of 50 questions to overstep the Spring certification.

    In general, If y'all tin reply those questions along amongst David Mayer's online Spring Mock exam, in addition to thus y'all are cook for the existent exam.



    Official Spring_Web_4.2_Study_Guide
    This is a gratis written report guide for Spring Web application developer certification 4.2 version from the Pivotal itself. It contains some often asked inquiry in addition to information close the examination itself. It too contains questions which bear witness whether y'all know the essential concepts or not. These Spring questions are too a proficient resources for an interview. 

     for becoming Pivotal certified Spring developer Top five Spring Certification Study Guides for Core, Web, in addition to Enterprise Integration Exams


    That's all close some of the best resources to fix for Spring certifications. We own got looked at some of the best written report guides available for Spring core, Spring spider web developer examination in addition to Spring Enterprise Integration Specialist exam. I own got too shared a distich of books to acquire Spring framework inward full general before reading a written report guide to focus to a greater extent than on examination topics. The written report guide offers several produce goodness over conventional majority e.g. they encompass all examination topics in addition to too own got topic-wise quizzes, multiple selection questions to fix better.

    Thanks for reading this article, if y'all uncovering these resources useful in addition to thus delight part amongst your friends in addition to colleagues. If y'all own got whatever other resources which is useful for preparing Spring certification, in addition to thus experience gratis to part amongst us.

    P.S. -  If y'all are an experienced Java developer and using Spring framework for three to five years in addition to desire to acquire certified for your science I propose y'all become through David Mayer's Online Spring Mock test, It's a gratis bear witness in addition to if y'all tin score over 80% in addition to thus y'all are cook for the existent exam.

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

    Problem:
    I was trying to run a HelloWorld plan 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 move on if you lot are @ComponentScanning a springframework bundle (e.g. if you lot pose a @ComponentScan inwards the default bundle yesteryear 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 too I was using @SpringBootApplication musical note 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 yesteryear 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 move on if you lot are @ComponentScanning a boundary framework bundle (e.g. if you lot pose a @ComponentScan inwards the default bundle yesteryear mistake)


    Solution:

    The argue was next conflicting dependencies whihc I stimulate got already had inwards my project, exactly 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 unloosen but Spring Boot 1.2.7 spider web starter ask higher version of library. The cast which was inwards enquiry i.e. SmartInitializingSingleton wasn't introduce inwards before version of library.

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

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



    That's all almost how to produce "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 last careful non to mix private dependency amongst Spring kicking starter dependency unless you lot certain that the explicit dependency is complete, non introduce equally purpose of starter dependency.

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

    Thanks for reading this article too then far. If you lot are facing the same occupation too if this article helped you lot to solve your occupation delight part amongst your friends too colleagues. 

    Friday, November 8, 2019

    Top Fifteen Restrain Kick Interview Questions Amongst Answers For Java/Jee Programmers

    Hello guys, if yous are preparing for your adjacent Java interview together with Job description mentioned most Spring framework, together with so yous should also gear upward about Spring Boot interview questions to avoid disappointment. The Spring Boot is similar a shot the criterion way to exercise Spring framework for Java evolution together with almost all the companies are moving from the traditional way of using Spring Framework to to a greater extent than modern Spring Boot way. Gone are the days, where questions similar guide maintain yous used Spring Boot was asked to the developer. Nowadays interview expects to a greater extent than cognition of Spring Boot from candidates together with in that place are reasons for it, which we'll explore inwards this article.

    Spring Boot aims to simplify Java evolution alongside Spring yesteryear removing major hurting points alongside abide by to configuration, dependency management together with ease of development.  As Craig Walls position inwards Spring kicking inwards Action, It's likely the best matter happened to Java afterward JDK 1.5 release and the introduction of Spring Framework itself about fifteen years back.

    It introduces a host of features e.g. starter dependency, auto-configuration, embedded server, Spring Boot CLI, Spring Actuator, Spring Initializer etc to accept the Java evolution alongside Spring to adjacent score together with that's why Spring Boot interview questions are becoming increasingly mutual inwards Java interviews.

    In guild to answer Spring Boot query alongside confidence, yous non alone know what occupation Spring Boot solves but also in-depth cognition of about of its substance features similar auto-configuration together with starter dependencies. These 2 features eliminate a lot of configuration together with setup piece of work from Spring-based Java application.

    Btw, If yous are non familiar alongside them I start propose yous buy the farm through a beginners shape similar Spring Boot Essentials to acquire up-to-speed. Once yous guide maintain skilful cognition of Spring Boot, yous tin endeavor these questions.




    10 Spring Boot Interview Questions for Java Developers

    Here is my listing of about of the most mutual Spring Boot Interview Questions from Java interviews. These questions embrace most of Spring Boot features e.g. auto-configuration, starter dependencies, Spring Actuator, Spring Initializer, Spring Boot CLI etc.

    They are also collected from Java interviews for both intermediate together with experienced Java developers e.g. from 2 to five years of experience.


    1. What is Spring Boot? Why should yous exercise it?
    Spring Boot is about other Java framework from Sring umbrella which aims to simplify the exercise of Spring Framework for Java development. It removes most of the hurting associated alongside dealing alongside Spring e.g. a lot of configuration together with dependencies together with a lot of manual setups.

    Why should yous exercise it? Well, Spring Boot non alone provides a lot of convenience yesteryear auto-configuration a lot of things for yous but also improves the productivity because it lets yous focus alone on writing your describe of piece of work organisation logic.

    For example, you don't demand to setup a Tomcat server to run your spider web application. You tin only write code together with run it every bit Java application because it comes alongside an embedded Tomcat server. You tin also create a JAR file or WAR file for deployment based on your convenience.

    In short, in that place are many reasons to exercise Spring Boot. In fact, it's similar a shot the criterion way to prepare Java application alongside Spring framework.



    2. What are about of import features of using Spring Boot?
    This is a skilful subjective query together with used yesteryear the interviewer to guess the sense of a candidate alongside Spring Boot. Anyway, next are about of the of import features of Spring Boot framework:

    1. Starter dependency
    This characteristic aggregates mutual dependencies together. For example, if yous desire to prepare Spring MVC based RESTful services together with so instead of including Spring MVC JAR together with Jackson JAR file into classpath yous tin only specify spring-boot-web-starter together with it volition automatically download both those JAR files. Spring Boot comes alongside many such starter dependencies to ameliorate productivity.

    2. Auto-Configuration
    This is about other awesome features of Spring Boot which tin configure many things for you. For example, If yous are developing Spring spider web application together with Thymeleaf.jar is nowadays on the classpath together with so it tin automatically configure Thymeleaf template resolver, see resolver, together with other settings. H5N1 skilful cognition of auto-configuration is required to buy the farm an experienced Spring Boot developers.

    3. Spring Initializer
    H5N1 spider web application which tin create initial projection construction for you. This simplifies initial projection setup part.

    4. Spring Actuator
    This characteristic provides a lot of insights of a running Spring kicking application. For example, yous tin exercise Actuator to detect out which beans are created inwards Spring's application context together with which asking path are mapped to controllers.

    5. Spring CLI
    This is about other awesome characteristic of Spring Boot which actually takes Spring evolution into adjacent level. It allows yous to exercise Groovy for writing Spring kicking application which way a lot to a greater extent than concise code.

    If yous are interested inwards learning to a greater extent than most these essential Spring Boot features together with so Dan Vega's Learn Spring Boot - Rapid Spring Application Development is a nifty house to start with.


     if yous are preparing for your adjacent Java interview together with Job description mentioned most Spr Top fifteen Spring Boot Interview Questions alongside Answers for Java/JEE Programmers





    3. What is auto-configuration inwards Spring boot? how does it help? Why Spring Boot is called opinionated?
    There are a lot of questions inwards this i query itself, but let's start tackle auto-configuration. As explained inwards the previous example, it automatically configures a lot of things based upon what is nowadays inwards the classpath.

    For example, it tin configure JdbcTemplate if its nowadays together with a DataSource edible bean are available inwards the classpath. It tin fifty-fifty exercise about basic spider web safety materials if Spring safety is nowadays inwards the classpath.

    Btw, if yous are non familiar alongside saltation safety library together with so banking venture check out Spring Security Masterclass to acquire to a greater extent than most it. It's i of the most of import tools to secure modern-day Java application.

    Anyway, the betoken is auto-configuration does a lot of piece of work for yous alongside abide by to configuring beans, controllers, see resolvers etc, so it helps a lot inwards creating a Java application.

    Now, the big questions come, why it's considered opinionated? Well because it makes a judgment on its own. Sometimes it imports things which yous don't want, but don't worry, Spring Boot also provides ways to override auto-configuration settings.

    It's also disabled yesteryear default together with yous demand to exercise either @SpringBootApplication or @EnableAutoConfiguration annotations on the Main shape to enable the auto-configuration feature. See Spring Boot Essentials for learning to a greater extent than most them.




    4. What is starter dependency inwards Spring Boot? how does it help?
    This query is to a greater extent than oft than non asked every bit a follow-up of the previous query every bit it's quite similar to auto-configuration together with many developers acquire confused betwixt both of them. As the shout out suggests, starter dependency bargain alongside dependency management.

    After examining several Spring-based projects Spring guys notice that in that place is ever about laid of libraries which are used together e.g. Spring MVC alongside Jackson for creating RESTful spider web services. Since declaring a dependency inwards Maven's pom.xml is the pain, they combined many libraries into i based upon functionality together with created this starter package.

    This non alone frees yous from declaring many dependencies but also fees yous from compatibility together with version mismatch issue. Spring Boot starter automatically pulls compatible version of other libraries so that yous tin exercise them without worrying most whatever compatibility issue.



    5. What is the divergence betwixt @SpringBootApplication together with @EnableAutoConfiguration annotation?
    Even though both are essential Spring Boot application together with used inwards the Main shape or Bootstrap shape in that place is a subtle divergence betwixt them. The @EnableAutoConfiguration is used to enable auto-configuration but @SpringBootApplication does a lot to a greater extent than than that.

    It also combines @Configuration together with @ComponentScan annotations to enable Java-based configuration together with constituent scanning inwards your project.

    The @SpringBootApplication is inwards fact combination of @Configuration, @ComponentScan together with @EnableAutoConfiguration annotations. You tin also banking venture check Spring Boot MasterClass to acquire to a greater extent than most this annotation together with it's used.

    Also, this Spring Boot query was latterly asked to i of my friends inwards his final interview alongside a big Investment bank. He was interviewing for a front-office Java spider web application which uses Spring Boot inwards the back-end.



    6. What is Spring Initializer? why should yous exercise it?
    One of the hard things to start alongside a framework is initial setup, especially if yous are starting from scratch together with yous don't guide maintain a reference setup or project. Spring Initializer addresses this occupation inwards Spring Boot.

    It's zero but a spider web application which helps yous to create initial Spring kicking projection construction together with provides Maven or Gradle gear upward file to gear upward your code.

    I highly recommend to exercise it if yous are starting the start time. If yous desire about assistance, yous tin banking venture check out this Spring Boot MasterClass.

     if yous are preparing for your adjacent Java interview together with Job description mentioned most Spr Top fifteen Spring Boot Interview Questions alongside Answers for Java/JEE Programmers




    7. What is Spring Actuator? What are its advantages?
    This is an interesting Spring Boot query together with mostly asked on Java roles which also has about back upward responsibility. Spring Actuator is about other cool Spring Boot characteristic which allows seeing within a running application.

    Yes, yous read it correctly. It allows yous to run across within an application. Since Spring Boot is all most auto-configuration it makes debugging hard together with at about betoken inwards time, yous desire to know which beans are created inwards Spring's Application Context together with how Controllers are mapped. Spring Actuator provides all that information.

    It provides several endpoints e.g. a REST endpoint to recollect this form of information over the web. It also provides a lot of insight together with metrics most application wellness e.g. CPU together with retentivity usage, number of threads etc.

    It also comes alongside a remote rhythm out which yous tin exercise to securely buy the farm within Spring Boot application together with run about command to let out the same laid of data. You tin fifty-fifty exercise JMX to command this behaviour at runtime.

    Btw, it's of import to secure your Spring Actuator endpoints because it exposes a lot of confidential information together with a potentially unsafe one-two. For example, yesteryear using /showdown endpoint yous tin kill a Spring Boot application.

    But, don't worry. You tin exercise Spring Security to secure Spring Actuator endpoints. If yous are non familiar alongside Spring Security together with so yous tin banking venture check out Spring Security Certification Class to acquire most it.



    8. What is Spring Boot CLI? What are its benefits?
    Spring Boot CLI is a command describe interface which allows yous to create Spring-based Java application using Groovy. Since it's used Groovy, it allows yous to create Spring Boot application from the command describe without ceremony e.g. yous don't demand to define getter together with setter method, or access modifiers, render statements etc.

    It's also really powerful together with tin auto-include a lot of library inwards Groovy's default packet if yous tumble out to exercise it.

    For example, if yous exercise JdbcTempalte, it tin automatically charge that for you. If yous are interested inwards learning Spring Boot CLI, I recommend reading Spring Boot inwards Action book, about other masterpiece from Craig Walls afterward Spring inwards Action.

     if yous are preparing for your adjacent Java interview together with Job description mentioned most Spr Top fifteen Spring Boot Interview Questions alongside Answers for Java/JEE Programmers



    9. Where exercise yous define properties inwards Spring Boot application?
    You tin define both application together with Spring kicking related properties into a file called application.properties. You tin create this file manually or yous tin exercise Spring Initializer to create this file, albeit empty.

    You don't demand to exercise whatever special configuration to instruct Spring Boot charge this file. If it exists inwards classpath together with so Spring Boot automatically loads it together with configure itself together with application code according.

    For example, yous tin exercise to define a belongings to modify the embedded server port inwards Spring Boot, which is also our adjacent question.



    10. Can yous modify the port of Embedded Tomcat server inwards Spring boot? If Yes, How?
    Yes, nosotros tin modify the port of Embedded Tomcat Server inwards Spring Boot yesteryear adding a belongings called server.port inwards the application.properties file.

    As explained inwards the previous question, this belongings file is automatically loaded yesteryear Spring Boot together with tin survive used to configure both Spring Boot every bit good every bit application code.

    If yous demand an example, yous tin run across this measuring yesteryear measuring tutorial to modify the port of Embedded Tomcat Server inwards Spring Boot. You tin farther see Learn Spring Boot inwards 100 Steps to acquire to a greater extent than most essential Spring Boot concepts together with how to exercise them inwards a existent project.

     if yous are preparing for your adjacent Java interview together with Job description mentioned most Spr Top fifteen Spring Boot Interview Questions alongside Answers for Java/JEE Programmers



    11. What is the divergence betwixt an embedded container together with a WAR?
    The primary divergence betwixt an embedded container together with a WAR file is that yous tin Spring Boot application every bit a JAR from the command prompt without setting upward a spider web server. But to run a WAR file, yous demand to start laid upward a web server similar Tomcat which has Servlet container together with and so yous demand to deploy WAR there.


    12. What embedded containers does Spring Boot support?
    Spring Boot back upward 3 embedded containers: Tomcat, Jetty, together with Undertow. By default, it uses Tomcat every bit embedded containers but yous tin modify it to Jetty or Undertow.


    13. What are about mutual Spring Boot annotations?
    Some of the most mutual Spring Boot annotations are @EnableAutoConfiguration, @SpringBootApplication, @SpringBootConfiguration, together with @SpringBootTest.

    The @EnableAutoConfiguration is used to enable auto-configuration on Spring Boot application, field @SpringBootApplication is used on the Main class to allow it to run a JAR file. @SpringBootTest is used to run unit of measurement attempt on Spring Boot environment.


    14. Can yous shout out about mutual Spring Boot Starter POMs?
    Some of the most mutual Spring Boot Start dependencies or POMs are spring-boot-starter, spring-boot-starter-web, spring-boot-starter-test. You tin exercise spring-boot-starter-web to enable Spring MVC inwards Spring Boot application.


    15. Can yous command logging alongside Spring Boot? How?
    Yes, nosotros tin command logging alongside Spring Boot yesteryear specifying log levels on application.properties file. Spring Boot loads this file when it exists inwards the classpath together with it tin survive used to configure both Spring Boot together with application code.

    Spring Boot uses Commons Logging for all internal logging together with yous tin modify log levels yesteryear adding next lines inwards the application.properties file:

    logging.level.org.springframework=DEBUG
    logging.level.com.demo=INFO


    That's all most about of the common Spring Boot Interview Questions for Java developers. If yous are preparing for Java evolution interview where Spring Boot is required every bit a science together with so yous should survive familiar alongside these interview questions. They non alone assist yous to exercise good inwards your interview but also encourage yous to acquire cardinal Spring Boot concepts inwards details to brand the best exercise of it.

    Further Learning
    Spring Framework Master Class - Beginner to Expert
    Master Microservices alongside Spring Boot together with Spring Cloud
    Master Hibernate together with JPA alongside Spring Boot inwards 100 Steps
    Spring Boot Reference Guide
    5 Free Spring Framework together with Spring Boot Courses
    Spring Boot: Efficient Development, Configuration, together with Deployment

    Thanks for reading this article so far. If yous similar these Spring Boot Interview Questions together with so delight portion alongside your friends together with colleagues. If yous guide maintain whatever feedback or dubiousness together with so delight drib a note.

    Thursday, November 7, 2019

    Difference Betwixt @Springbootapplication Vs @Enableautoconfiguration Annotations Inward Trammel Boot

    Even though both @SpringBootApplication as well as @EnableAutoConfiguration tin hold out used to enable the auto-configuration characteristic of Spring Boot in that place is a subtle departure betwixt them. The @SpringBootApplication does much to a greater extent than than what @EnableAutoConfiguration do. It's genuinely a combination of 3 annotations: @Configuration which is used inward Java-based configuration on Spring framework, @ComponentScan to enable constituent scanning of components you lot write e.g. @Controller classes, as well as @EnableAutoConfgiuration itself, which is used to enable auto-configuration inward Spring Boot application. Spring Boot designers realize that these 3 annotations are oftentimes used together hence they bundled them into @SpringBootApplicaiton. Now, instead of 3 annotations you lot simply demand to specify 1 annotation on your Main class.

    What is the departure betwixt @EnableAutoConfiguration as well as @SpringBootApplication is too a mutual Spring Boot interview interrogation as well as it was late asked 1 of my friends on his Java interview. Given the popularity of Spring Boot framework, it's skillful to know such questions earlier you lot become for your side past times side Java interview.

    In this article, I'll explicate what does the @SpringBootApplication as well as @EnableAutoConfiguration practise as well as highlight about of import departure betwixt them hence that you lot tin respond this interrogation alongside confidence if you lot plow over to come across them inward your interview.




    1. What is Auto-Configuration inward Spring Boot?

    If you lot don't know, Spring Boot aims to simplify Java evolution alongside Spring framework. Currently, Spring does a lot for you lot but inward return, it too asks a lot from you lot inward damage of configuration as well as dependency management, Spring Boot aims to solve that problem.

    The Spring Boto auto-configuration feature tries to automatically configure your Spring application based upon the JAR dependency you lot get got added inward the classpath.

    For example, if HSQLDB is nowadays on your classpath as well as you lot get got non configured whatsoever database manually, Spring volition auto-configure an in-memory database for you.

    By default, this auto-configuration characteristic is non enabled as well as you lot demand to opt-in for it past times adding the @EnableAutoConfiguration or @SpringBootApplicaiton annotations to 1 of your @Configuration classes, by as well as large the Main bird which is used to run your application.

    Though, this is simply the tip of the iceberg. Spring Boot auto-configuration takes to a greater extent than than 200 such determination to configure your application, If you lot are interested inward learning to a greater extent than then Spring Framework Master Class - Beginner to Expert is a skillful course of report to larn Spring Boot inward depth.

     in that place is a subtle departure betwixt them Difference betwixt @SpringBootApplication vs @EnableAutoConfiguration annotations inward Spring Boot




    2. Difference betwixt @EnableAutoConfiguration as well as @SpringBootApplication

    Now that nosotros know what is @SpringBootApplication as well as @EnableAutoConfiguration annotation as well as what practise they do, it's fourth dimension to highlight about of import departure betwixt them.

    Here is a duad of worth-noting departure betwixt @SpringBootApplication as well as @EnableAutoConfiguration annotations of Spring Boot:

    1. Availability
    The @SpringBootApplicaiton is relatively novel than @EnableAutoConfiguration. It was introduced inward Spring Boot 1.2 release piece @EnableAutoConfiguation is nowadays shape the Spring Boot 1.0 release.


    2. Purpose
    The clear piece of work of @EnableAutoConfiguration is to enable automatic configuration characteristic of Spring Boot application which automatically configures things if sure as shooting classes are nowadays inward Classpath e.g. it tin configure Thymeleaf TemplateResolver as well as ViewResolver if Thymeleaf is nowadays inward the classpath.

    On the other hand, @SpringBootApplication does 3 things, it allows you lot to run the Main bird every bit a JAR alongside an embedded container. It enables Java configuration as well as it too enables Component Scanning.


    3. Uses
    It's not mandatory to position @SpringBootApplication to create a Spring Boot application, you lot tin even hence occupation @Configuration as well as @EnableAutoConfiguration individually every bit shown inward the illustration given inward side past times side point.


    4. Control
    The @EnableAutoConfiguration annotation allows you lot to selectively exclude sure as shooting classes from auto-configuration using exclude attribute every bit shown below:

    @Configuration @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) public class MyConfiguration {   //.. Java code }

    If the bird is non on the classpath, you lot tin occupation the excludeName attribute of the @EnableAutoConfiguration annotation as well as specify the fully qualified bird name.

    If you lot desire to larn to a greater extent than well-nigh this annotation, I advise you lot reading Craig Walls' (author of Spring inward Action) about other masterpiece Spring Boot inward Action.

     in that place is a subtle departure betwixt them Difference betwixt @SpringBootApplication vs @EnableAutoConfiguration annotations inward Spring Boot



    3. Important points

    Now that you lot sympathise the departure betwixt @EnableAutoConfiguration as well as @SpringBootApplication, it's fourth dimension to revise about of import points well-nigh these 2 of import annotations.

    1. You should annotate the Main bird or Bootstrap bird alongside the @SpringBootApplication, this volition permit you lot to run every bit a JAR alongside embedded spider web server Tomcat. If you lot desire you lot tin alter that to Jetty or Undertow.


    2. The @SpringBootApplication is a combination of 3 annotations @Configuration (used for Java-based configuration), @ComponentScan (used for constituent scanning), as well as @EnableAutoConfiguration (used to enable auto-configuration inward Spring Boot).


    3. The @EnableAutoConfiguration annotations enable auto-configuration features of Spring Boot which configures modules based on the presence of sure as shooting classes on the classpath. For example, if Thymeleaf JAR is nowadays inward classpath as well as Spring MVC is enabled e.g. using spring-boot-web-starter parcel as well as hence it tin automatically configure template resolver as well as persuasion resolver for you.


    4. The @EnableAutoConfiguration annotation is based on @Conditional annotation of Spring 4.0 which enables conditional configuration.


    5. In instance of auto-configuration, manually declared beans tin override beans automatically created past times auto-configuration feature. This is achieved past times using @ConditionalOnMissingBean of Spring 4.0


    6. If you lot are using @EnableAutoConfiguration classes as well as hence you lot tin selectively exclude sure as shooting classes from auto-configuration past times using exclude every bit shown below:

    @EnableAutoConfiguration(exclude=DataSourceAutoConfiguration.class)


    7. The @SpringBootApplication annotation too provides aliases to customize the attributes of @EnableAutoConfiguration as well as @ComponentScan annotations.


    That's all well-nigh the departure betwixt @SpringBootApplication as well as @EnableAutoConfiguration annotations of Spring Boot. As you lot learned, the @SpringBootApplication makes it tardily to enable auto-configuration as well as create a Bootstrap bird past times reducing the position out of annotations you lot usually demand i.e. instead of 3 annotations you lot simply demand one. But, if you lot demand to a greater extent than command over autoconfiguration as well as hence you lot should occupation @EnableAutoConfiguration, which allows you lot to exclude classes from auto-configuration.


    Further Learning
    Spring Framework Master Class - Beginner to Expert
    Master Microservices alongside Spring Boot as well as Spring Cloud
    Master Hibernate as well as JPA alongside Spring Boot inward 100 Steps
    Spring Boot Reference Guide
    REST alongside Spring MasterClass past times Eugen Parsaschiv
    Spring Boot: Efficient Development, Configuration, as well as Deployment

    Thanks for reading this article hence far. If you lot similar this article as well as my explains of departure betwixt @SpringBootApplication as well as @EnableAutoConfiguration as well as hence delight portion alongside your friends as well as colleagues. If you lot get got whatsoever questions or feedback as well as hence delight drib a note.