When should I use the @Enableautoconfiguration annotation and how does it work?

Asked

Viewed 1,381 times

4

The Annotation EnableAutoConfiguration should be used in what type of project? and how it works in the application?

1 answer

4


Delfino, this note is part of the Project Spring-Boot, interesting project for those who want to develop Micro-services. One of its main features of Spring-Boot is to allow the Spring Application Context to be automatically configured based on the jars.

Annotation Properties:

  • Auto-configuration is always done after the Beans defined by you having been registered.

  • Auto-configuration tries to be as smart as possible to configure your application’s interfaces and decreases your role as you set the settings manually.

  • Another important feature of the annotation, is its property exclude, which you can use to define the classes you want that do not undergo automatic settings.

package hello;

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;

@Controller
@EnableAutoConfiguration
public class SampleController {

    @RequestMapping("/")
    @ResponseBody
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleController.class, args);
    }
}

Here’s another important link for you:

http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-auto-configuration.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.