Spring Java Configuration之@EnableAutoConfiguration

官网上的解释是这样的:

Enable auto-configuration of the Spring Application Context, attempting to guess and configure beans that you are likely to need. Auto-configuration classes are usually applied based on your classpath and what beans you have defined.

Auto-configuration tries to be as intelligent as possible and will back-away as you define more of your own configuration. You can always manuallyexclude() anyconfiguration that you never want to apply (use excludeName() if you don'thave access to them). You can also exclude them via thespring.autoconfigure.exclude property. Auto-configuration is always appliedafter user-defined beans have been registered.

The package of the class that is annotated with @EnableAutoConfiguration has specific significance and is often used as a 'default'. For example, it will be usedwhen scanning for@Entity classes. It is generally recommended that you place@EnableAutoConfiguration in a root package so that all sub-packages and classescan be searched.

Auto-configuration classes are regular Spring Configuration beans. They are located using the SpringFactoriesLoader mechanism (keyed against this class).Generally auto-configuration beans are@Conditional beans (mostoften using @ConditionalOnClass and@ConditionalOnMissingBean annotations).

首先,顾名思义,@EnableAutoConguration是和自动化配置相关的东西。

官网的第一段话主要是说,Spring应用上下文的自动化配置,尝试去猜测和配置你需要的bean。这些被自动化配置的类通常在classpath路径下,或者是你自己定义的bean。

第二段话主要是说,你可以使用exclude来排除那些你不想被自动化配置的类。

第三段是讲:被@AutoConfiguration注解的类所在的包有着特殊的意义,他们通常被认为是默认的包,并对其及下属的包进行扫描。

第四段前半句是说,被自动配置的类通常是在@Configuration里面配置的类。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值