3

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?

Phil
  • 46,436
  • 33
  • 110
  • 175
  • I don't think that is intended, yml are spring-boot's properties file, and not spring-core configuration resources. You can however subclass `ComponentScanBeanDefinitionParser` to make it load a yml file if that's what you prefer. – Jeremy Grand Aug 18 '17 at 07:13

2 Answers2

2

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.

Chaitanya
  • 15,403
  • 35
  • 96
  • 137
0

that is unnecessary,because yml file belongs to spring boot,

lloiacono
  • 4,714
  • 2
  • 30
  • 46
peter
  • 16
  • 1