What you need to understand is that web.xml
and application-context.xml
serve two completely different purposes.
The first one is used to configure an application to run in a servlet container while the second one is used in order to provide Spring configuration. web.xml
can of course be replaced by Java based configuration when the container supports servlet spec 3.0 or later.
When running a Spring MVC test in order to test a Spring controller, web.xml
is not used at all, since the test is not run in a servlet container because the test framework mocks out all the dependencies. You could easily have Spring MVC tests for code that pass, but not have a web.xml
at all if you are in a TDD environment.
In conclusion, the concerns addressed by web.xml
and application-context.xml
are orthogonal and one can be used without caring about the other.
Also to clarify, the configuration supplied by web.xml
or the WebApplicationInitializer
alternative cannot be supplied in application-context.xml