Advertisement

NO WEB.XML ? || Spring MVC Java based configuration || WebApplicationInitializer || Part 2

NO WEB.XML ? || Spring MVC Java based configuration || WebApplicationInitializer || Part 2 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.



Make sure to join my private Facebook page.

“SeleniumExpress - Support"

you can ask for support in my website forum.



Subscribe to my youtube channel.



Music :

-----------

credits : -

(intro)

Adventures by A Himitsu

Creative Commons — Attribution 3.0 Unported— CC BY 3.0



Music released by Argofox

Music provided by Audio Library



intro template :
www.youtube.com/Alexbau01

webapplicationinitializer spring,no web.xml,spring mvc java based configuration,spring mvc java,what is web.xml,web.xml in spring mvc,web.xml file,replacement in spring,spring mvc annotation based configuration example,spring mvc no xml,dispatcher servlet,spring mvc interview questions and answers,spring mvc tutorial for beginners,spring mvc 5 tutorial,spring mvc interview questions and answers for experienced in java,spring mvc by selenium express,abhilash,

Post a Comment

0 Comments