I read about the difference between a web context and an application context. It seems to understand the difference, but constantly stumble on a rake. In the deployment descriptor, the specified context configurations
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/root-context.xml</param-value> </context-param> <servlet> <servlet-name>appServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/servlet-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> In servlet-context.xml I tried to leave only the presentation layer
<context:component-scan base-package="com.example"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> In root-context.xml, on the contrary, I want to load everything except controllers.
<context:component-scan base-package="com.example"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> and by importing I connect the configuration of the data access layer, transactions, security, cache, etc.
Only the @Transactional annotation, for example, refuses to work in the service layer until I put the <tx:annotation-driven transaction-manager="transactionManager"/> in the servlet-context.xml. That is, bins marked with annotations @Service and @Repository somehow loaded into the web context? Why is that? Or do I still misunderstand the difference between contexts?