springboot Learning: automatic assembly

Spring automatic assembly can be assembled by relying on the corresponding bean you have added. For example, you have a HSQLDB path inside, you need is not particularly specified database connection manually bean, Spring automatically assembling a memory database.

When in use, you need to add @EnableAutoConfiguration or @SpringBootApplication comment on @Configuration stated configuration class.

At any time, you can begin to define your own configuration to replace a specific part of the automatic configuration. For example, if you add your own data source bean, the default embedded database support will disappear.

You can also disable the automatic assembly of special classes. @EnableAutoConfiguration the property can disable you do not want to exclude the use of configuration. Such as:

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

If the class is not in the path, you can be used @EnableAutoConfiguration excludeName property and specify the fully qualified name.

Of course, also possible to use the automatic configuration control list spring.autoconfigure.exclude property classes to be excluded.

It depends on personal preference.

Although the automatic assembly of the class is public, but disabled the automatic assembly of the time, only the names of these classes is that we used, rather than a method or class within the mosaic that uses the class name to qualify.

Published 16 original articles · won praise 0 · Views 299

Guess you like

Origin blog.csdn.net/weixin_43859070/article/details/104068147