简体   繁体   中英

How to set Spring component scan in the Spring YML configuration file?

I can see that I can do component scan and restrict what packages are scanned using XML file.

<beans>
    <context:component-scan base-package="com.mycompany"/>
</beans>

How can I do the same in YML file?

YML is just to load properties, refer to this 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.

This is also explained here .

You can also use YAML ('.yml') files as an alternative to '.properties'.

So you cannot define/configure beans using YML.

这是不必要的,因为yml文件属于spring boot,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM