I am working on a spring mvc project.. When I place <mvc:annotation-driven/> tag in dipatcherservlet-servlet.xml then getting trouble in accessing page (Unable to access 404 status code).. dipatcherservlet-servlet.xml contains other bean configurations like InternalResouceViewResolver..
When I place following 3 tags in separate xml file then everything going excellent..
Also, you put your mvc-dispatcher-servlet.xml in the list of config files for the ContextLoaderListener, which is used to make an ApplicationContext for your middle tier beans, there shouldn't be any web tier beans in those files. The dispatcher servlet xml should be used by the Dispatcher Servlet for it to create a second ApplicationContext that only stores your Web Tier beans.
So in your mvc-dispatcher-servlet.xml it should have these tags only
In your second config file you can have benas for your Services, Repositories and other middle tier beans like DataSource, TransactionManager.
I think in the end the reason why your first didn't work was because you might have had a typo in the xml file name.
I would just like to further explain what Mark has already said just to make sure you understand.
When you do something like this
it is functionally equivalent to the following
What this means is you are running into one of those convention over configuration situations. Now what that means for your set up is you are with what you have posted creating the beans defined in mvc-dispatcher-servlet.xml in the root application context and then overriding them in the servlet context with the exact same thing.
Best practice is to do what Mark said and remove mvc-dispatcher-servlet.xml from your context-params as all of these beans go into your root context. This way you will have your web beans correctly scoped and only available at the dispatcher servlet.
Now if you were to want to keep all of your beans in just the root context (I am not advising this here) then you would get rid of mvc-dispatcher-servlet.xml as the name is misleading and put those beans in your application-context.xml. Then you would define the dispatcher servlet like this
This would in essence tell spring don't do your convention over configuration stuff I don't want a servlet scoped context I am going to put everything in the root context.