Spring YML配置文件中如何设置Spring组件扫描?
How to set Spring component scan in the Spring YML configuration file?
我可以看到我可以进行组件扫描并限制使用 XML 文件扫描的包。
<beans>
<context:component-scan base-package="com.mycompany"/>
</beans>
如何在 YML 文件中做同样的事情?
YML只是加载属性,参考这个Spring documentation。
24.6 Using YAML instead of Properties YAML is a superset of JSON, and as such is a very convenient format for specifying hierarchical
configuration data. The SpringApplication class will automatically
support YAML as an alternative to properties whenever you have the
SnakeYAML library on your classpath.
这个也有解释here。
You can also use YAML ('.yml') files as an alternative to
'.properties'.
所以你不能 define/configure 使用 YML 的 bean。
不需要,因为yml文件属于spring引导,
我可以看到我可以进行组件扫描并限制使用 XML 文件扫描的包。
<beans>
<context:component-scan base-package="com.mycompany"/>
</beans>
如何在 YML 文件中做同样的事情?
YML只是加载属性,参考这个Spring documentation。
24.6 Using YAML instead of Properties YAML is a superset of JSON, and as such is a very convenient format for specifying hierarchical configuration data. The SpringApplication class will automatically support YAML as an alternative to properties whenever you have the SnakeYAML library on your classpath.
这个也有解释here。
You can also use YAML ('.yml') files as an alternative to '.properties'.
所以你不能 define/configure 使用 YML 的 bean。
不需要,因为yml文件属于spring引导,