The @Springbootapplication Tone Example Inwards Coffee + Jump Boot

Hello guys, today, we'll larn near the @SpringBootApplication annotation, i of the most of import annotations from pop Spring Boot framework, which has changed the way Java developers job Spring framework for writing Java applications. In this article, I'll explicate to y'all the pregnant of @SpringBootApplication as well as it's used inward a uncomplicated Spring Boot application. We job @SpringBootApplication annotation on our Application or Main flat to enable a host of features e.g. Java-based Spring configuration, element scanning, as well as inward item for enabling Spring Boot's auto-configuration feature.

If y'all stimulate got been using Spring Boot for a long fourth dimension as well as then y'all know that before nosotros necessitate to annotate our Application flat or Main flat alongside quite a lot of annotations to origin alongside like
  1. @Configuration to enable Java-based configuration, 
  2. @ComponentScan to enable element scanning, 
  3. and @EnableAutoConfiguration to enable Spring Boot's auto-configuration feature, 
but instantly y'all tin practise all that yesteryear only annotating your Application flat alongside @SpringBootApplication.

Btw, this annotation is available from Spring 1.2 onwards which agency if y'all are running on lower Spring Boot version as well as then y'all volition even thence necessitate to job the @Configuration, @CompnentScan, as well as @EnableAutoConfiguration if y'all necessitate those features.

And, if y'all desire to larn to a greater extent than near changes betwixt Spring 1.2 as well as Spring 2.0 or desire to larn Spring Boot from scratch, y'all tin also cheque out this Spring Boot For Beginners online course of written report on Udemy, i of the best course of written report to larn Spring Boot online. I actually similar the way teacher Nelson Djalo explains concepts as well as walks through examples.




1. The @SpringBootApplication Example

Here is a uncomplicated instance of how to write a Spring Boot application using @SpringBootApplication annotation. This code instance is taken from my before article near consuming RESTful spider web service using Spring. In this example, nosotros stimulate got used RestTempalte flat to swallow a RESTful spider web service.


package tool;  import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.client.RestTemplate;   @SpringBootApplication public class Hello implements CommandLineRunner {    private static in conclusion Logger log = LoggerFactory.getLogger(Hello.class);    public static void main(String args[]) {     SpringApplication.run(Hello.class);   }    @Override   public void run(String... args) throws Exception {      RestTemplate restTemplate = new RestTemplate();      Country dry reason = restTemplate.getForObject(         "http://www.services.groupkt.com/country/get/iso2code/US",         Country.class);      log.info(country.toString());    }  }

The Main flat serves 2 purposes inward a Spring Boot application: configuration as well as bootstrapping. First, it's the top dog Spring configuration flat as well as second, it enables the auto-configuration characteristic of Spring Boot application.

If y'all are interested inward learning to a greater extent than near essential Spring Boot features e.g. auto-configuration as well as Starter dependency as well as then Spring Boot Essentials is a expert course of written report to larn them quickly.

 i of the most of import annotations from pop Spring Boot framework The @SpringBootApplication annotation Example inward Java + Spring Boot





2. @SpringBootApplication = @Configuration + @ComponentScan + @EnableAutoConfiguration

The @SpringBootApplication annotation is a combination of the next 3 Spring annotations as well as provides the functionality of all 3 alongside only i occupation of code:

@Configuration
This annotation marks a flat every bit a Configuration flat inward Java-based configuration. This is especially of import if y'all favor Java-based configuration over XML configuration.  If y'all are non familiar alongside Java Based Configuration, See Spring Framework MasterClass - Beginners to Expert to larn essential Spring concepts inward depth.

 i of the most of import annotations from pop Spring Boot framework The @SpringBootApplication annotation Example inward Java + Spring Boot


@ComponentScan
This annotation enables component-scanning thence that the spider web controller classes as well as other components y'all practise volition hold upwardly automatically discovered as well as registered every bit beans inward Spring's Application Context. All the @Controller classes y'all write is discovered yesteryear this annotation.


@EnableAutoConfiguration
This annotation enables the magical auto-configuration characteristic of Spring Boot, which tin automatically configure a lot of materials for you.

For example, if y'all are writing a Spring MVC application as well as y'all stimulate got Thymeleaf JAR files on application classpath as well as then Spring Boot auto-configuration tin automatically configure Thymeleaf template resolver, stance resolver, as well as other settings automatically.

So, y'all tin state that @SpringBootApplication is a 3-in-1 annotation which combines the functionality of @Configuration, @ComponentScan, as well as @EnableAutoConfiguration.

It also marks the flat every bit a BootStrap flat which agency y'all tin runt it every bit a normal Java flat similar yesteryear running its JAR file from the command prompt every bit shown here, or only correct click as well as runs a Java programme inward Eclipse IDE.

5 Free Courses to Learn Spring as well as Spring Boot
  • 10 Tips to travel out a ameliorate Java Developer inward 2019
  • 5 Spring Security Courses to Learn Online
  • 3 Ways to Learn Spring Boot as well as Spring Cloud
  • 5 Courses to Learn Spring Boot inward 2019
  • Top five Courses to Learn Spring Framework inward Depth

  • That's all near reading this article thence far. If y'all similar @SpringBootApplication annotation as well as my explanation as well as then delight part alongside your friends as well as colleagues. If y'all stimulate got whatever questions or feedback as well as then delight drib a note.

    P. S. - If y'all are looking for a hands-on, code focuses course of written report to larn Spring five as well as Spring Boot, as well as then I also propose y'all to stimulate got a expect at the Eugen Paraschiv's Learn Spring: The Certification Class, i of the best course of written report to larn Spring five as well as Spring Boot 2 from scratch, inward a guided, code-focused way.

    Belum ada Komentar untuk "The @Springbootapplication Tone Example Inwards Coffee + Jump Boot"

    Posting Komentar

    Iklan Atas Artikel

    Iklan Tengah Artikel 1

    Iklan Tengah Artikel 2

    Iklan Bawah Artikel