spring boot中的jave注解学习

   在spring中,不仅框架作者会使用java注解,开发者也常使用。

  可以随手给个例子:在org.springframework.boot.autoconfigure.jdbc.DataSourceProperties中@ConfigurationProperties(prefix="spring.datasource"),这个注解的意思根据经验,就是使用注解读取了配置文件中以prefix为前缀的配置信息。自己可以想想其实现原理,而不必看源码。源码那么多,是看不完的,关键是自己理解,掌握其思想。

  关于@configuration的注解看这篇博文:https://www.cnblogs.com/duanxz/p/7493276.html,可以看到configuration相当于xml文件中的beans标签,其也常常和@bean,@component,@component注解一起使用。程序从java的main方法开始执行,如果没有类扫描注解(java或者xml),仍然无法发现这些配置文件。

  @bean和@component的差别,@component是spring自动探测,而bean需要使用@componentscand扫描。

  再看@Conditional(PooledDataSourceCondition.class),@ConditionalOnClass({DataSource.class,EmbeddedDatabaseType.class)

原文地址:https://www.cnblogs.com/Robin008/p/10234559.html