1

To work via annotations in Spring need to define:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"
    xmlns:context="http://www.springframework.org/schema/context">

    <context:annotation-config/>
</beans>

at

annotation-config.xml

But I created a simplest Spring boot Application (lets say I select lust Web in initialazr)

It works on annotations but there isn't any annotation-config.xml there and nor mentioning of , where is hidden?

J.J. Beam
  • 2,612
  • 2
  • 26
  • 55

1 Answers1

4

You only need to add <context:annotation-config /> or <context:component-scan /> (which implies annotation driven config) when using an ApplicationContext implementation that doesn't support annotations out-of-the-box.

When only using XML based configuration you also use one of the XML enabled ApplicationContext implementations, generally that would be XmlWebApplicationContext. With these you would need to instruct the ApplicationContext to enable annotation processing.

When using Java based configuration you generally use an annotation based ApplicationContext, default would be AnnotationConfigWebApplicationContext. Due to its nature of processing Java configuration classes it has annotation processing enabled by default.

Spring Boot uses the latter (it actually uses a specialized subclass for this). Hence you don't need to explicitly enable it.

M. Deinum
  • 115,695
  • 22
  • 220
  • 224