Configuring Vaadin without web.xml

There is always room for improvement in programming world. After my initial post about configuring Vaadin in 6 simple steps, one of my friends indicated that we could have used annotation based configuration to get rid of web.xml in our Vaadin configuration. Yes, he is right. It is possible to configure Vaadin with annotations without touching web.xml at all. Let’s see how it can be achieved;

Step 1: Add Servlet API dependency into your pom.xml, and update your project’s configuration


Step 2: Modify your HelloWorldUI as follows

public class HelloWorldUI extends UI {
	public static class ExtendedVaadinServlet extends VaadinServlet {

	protected void init(VaadinRequest request) {
		Button btn = new Button("Click Me!");
		btn.addClickListener(new ClickListener() {
			public void buttonclick(ClickEvent event) {
				Notification.show("Hello World!");

Step 3: Remove or comment out VaadinServlet configuration in web.xml

Just remove <servlet> and <servlet-mapping> elements in web.xml we had added in our previous post. Now restart your web container, and try to access http://localhost:8080/helloworld URL in your local environment to see the result. It should work without any problem as before.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.