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

4

Annotation EnableAutoConfiguration should be used on what kind of project? and how does it work in the application?

    
asked by anonymous 05.06.2015 / 01:16

1 answer

4

Delfino, this annotation is part of the Project Spring-Boot , an interesting project for those who want to develop Micro-services. One of its main Spring-Boot features 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 you defined.

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

  • Another important feature of the annotation is its exclude property, which you can use to define the classes you want not to have 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 is one more important link for you:

link

    
05.06.2015 / 22:15