The @Springbootapplication Musical Note Event Inwards Coffee + Throttle Boot

Advertisement

Masukkan script iklan 970x90px

The @Springbootapplication Musical Note Event Inwards Coffee + Throttle Boot

Jumat, 27 Maret 2020

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

If yous induce got been using Spring Boot for a long fourth dimension together with thence yous know that before nosotros postulate to annotate our Application degree or Main degree amongst quite a lot of annotations to showtime amongst like
  1. @Configuration to enable Java-based configuration, 
  2. @ComponentScan to enable ingredient scanning, 
  3. and @EnableAutoConfiguration to enable Spring Boot's auto-configuration feature, 
but right away yous tin practice all that yesteryear simply annotating your Application degree amongst @SpringBootApplication.

Btw, this annotation is available from Spring 1.2 onwards which way if yous are running on lower Spring Boot version together with thence yous volition yet postulate to utilisation the @Configuration, @CompnentScan, together with @EnableAutoConfiguration if yous postulate those features.

And, if yous desire to larn to a greater extent than nigh changes betwixt Spring 1.2 together with Spring 2.0 or desire to larn Spring Boot from scratch, yous tin also depository fiscal establishment jibe out this Spring Boot For Beginners online course of report on Udemy, i of the best course of report to larn Spring Boot online. I actually similar the way teacher Nelson Djalo explains concepts together with 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 nigh consuming RESTful spider web service using Spring. In this example, nosotros induce got used RestTempalte degree 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 lastly 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 province = restTemplate.getForObject(         "http://www.services.groupkt.com/country/get/iso2code/US",         Country.class);      log.info(country.toString());    }  }

The Main degree serves 2 purposes inward a Spring Boot application: configuration together with bootstrapping. First, it's the primary Spring configuration degree together with second, it enables the auto-configuration characteristic of Spring Boot application.

If yous are interested inward learning to a greater extent than nigh essential Spring Boot features e.g. auto-configuration together with Starter dependency together with thence Spring Boot Essentials is a proficient course of 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 iii Spring annotations together with provides the functionality of all iii amongst simply i trouble of code:

@Configuration
This annotation marks a degree every bit a Configuration degree inward Java-based configuration. This is especially of import if yous favor Java-based configuration over XML configuration.  If yous are non familiar amongst 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 together with other components yous practice volition live automatically discovered together with registered every bit beans inward Spring's Application Context. All the @Controller classes yous 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 yous are writing a Spring MVC application together with yous induce got Thymeleaf JAR files on application classpath together with thence Spring Boot auto-configuration tin automatically configure Thymeleaf template resolver, thought resolver, together with other settings automatically.

So, yous tin state that @SpringBootApplication is a 3-in-1 annotation which combines the functionality of @Configuration, @ComponentScan, together with @EnableAutoConfiguration.

It also marks the degree every bit a BootStrap degree which way yous tin runt it every bit a normal Java degree similar yesteryear running its JAR file from the command prompt every bit shown here, or simply correct click together with runs a Java programme inward Eclipse IDE.

5 Free Courses to Learn Spring together with Spring Boot
  • 10 Tips to acquire a amend Java Developer inward 2019
  • 5 Spring Security Courses to Learn Online
  • 3 Ways to Learn Spring Boot together with Spring Cloud
  • 5 Courses to Learn Spring Boot inward 2019
  • Top v Courses to Learn Spring Framework inward Depth

  • That's all nigh reading this article thence far. If yous similar @SpringBootApplication annotation together with my explanation together with thence delight part amongst your friends together with colleagues. If yous induce got whatever questions or feedback together with thence delight drib a note.

    P. S. - If yous are looking for a hands-on, code focuses course of report to larn Spring v together with Spring Boot, together with thence I also advise yous to accept a expect at the Eugen Paraschiv's Learn Spring: The Certification Class, i of the best course of report to larn Spring v together with Spring Boot 2 from scratch, inward a guided, code-focused way.