As we are setting up our spring MVC project with only java code, the first job is to remove any XML file we have. Well, Here is a million-dollar question. Can we run a web app without a web.xml file? If yes, then how? If No, Then why?
Well, the fact is we can deploy a web app without a web.xml file. The only catch is here that we should have the latest servlet container. We should have at least a servlet 3.0 + container to run our web-app to run a java web application.
Now, here comes another question. The web.xml file auto-detected by our webserver. So we do our dispatcher servlet configuration inside the web.xml file. But now as we are going to remove the web.xml file where we are going to write code for dispatcher servlet?
So, We will create a class and, we will implement an interface called WebApplicationInitializer. This interface is given by spring MVC to ensure a code-based configuration. The WebApplicationInitializer ensures that your class will be auto-detected by the webserver like a web.xml file.
The WebApplicationInitializer has a method called on startup that takes a servlet context as an argument. We need to create a dispatcher servlet object and, then we will add it to the servlet context reference. That's it. We are ready to go. The rest will be taken care of by tomcat.
So here is how we can do a spring MVC java based configuration with no web.xml file. The above approach will be a replacement for the web.xml file.
If you are looking for important spring MVC interview questions, It's a good one to prepare.
Any time you are getting stuck with issues, Feel free to ask for support.
#springmvc #WebApplicationInitializer #NoXML
You can send mail to seleniumexpress@gmail.com
you can ping me on my Facebook page.
/ seleniumexpress
Make sure to join my private Facebook page.
“SeleniumExpress - Support"
you can ask for support in my website forum.
www.seleniumex...
Subscribe to my youtube channel.
/ @seleniumexpress
Music :
-----------
credits : -
(intro)
Adventures by A Himitsu / a-himitsu
Creative Commons - Attribution 3.0 Unported- CC BY 3.0
creativecommons....
Music released by Argofox • A Himitsu - Adventures...
Music provided by Audio Library • Adventures - A Himitsu...
intro template :
/ alexbau01
7 сен 2024