How to Use Fragments and Annotations To Configure Your Web Application

posted by mthomas on October 11, 2011 09:10 AM

The Servlet 3 specification - implemented in Apache Tomcat 7 - allows web.xml fragments and annotations to be used to specify configuration information for a web application. This means that, instead of packaging up every configuration centrally in your web.xml file, every JAR can have its own xml fragment containing its own little bit of configuration for whatever classes are in that JAR. This makes it easy to add support for packages with very little effort. For instance, a Spring developer would no longer need to add the Spring application context to the web.xml file, rather they could take advantage of a web fragment in the Spring JAR that would automatically add this configuration information at runtime.

Annotations take this one step further, and allow developers to annotate code that dynamically configures application components such as Servlets and Filters. Java libraries and frameworks have been embracing annotations for some time. In fact, several IDE’s these days use annotations as a default, adding the @WebServlet annotation by default when you create a new Servlet in a dynamic web project.

Performance Impacts

Both annotations and web fragments will impact performance, particularly at application startup. Tomcat has to scan every class in every single jar file to detect if the class has been annotated as a Servlet, a Filter or Listener. This can add substantial time to application start up, which is not so much of a problem for production applications as they should start very infrequently, but it can be pretty problematic during development when you are repetitively restarting.

Tip: If you are not going to be using annotations or web-fragments, you should set your metadata-complete to true in your web.xml file to avoid the longer start up time. (web-app metadata-complete=""true"").

Support Impacts

Another complication is that it forces support staff and administrators to look in more places to answer the same question. For instance, if your administrator wants to know how is a web application going to respond to a request, prior to Servlet 3 they could just into the web.xml file and it would tell them everything they needed to know. Now, fragments and annotations spread configuration information out to several locations, so instead of just checking the Servlet definition in web.xml they may need to check the source code to find the url mapping. It forces support staff to know more about the application itself, and increases time to debug simply by adding more places to look.

Tip: Tomcat can log the equivalent merged web.xml that takes all of the fragments, all of the annotations, and produces you a fully aggregated web.xml file by setting the logEffectiveWebXml attribute on the Context element to true. The easiest way to do this is to set this for all applications by adding this setting to the global defaults in $CATALINA_BASE/conf/context.xml. I recommend taking this output and replacing the production web.xml file with this more complete one. It will help speed problem identification for support, and also when used with the metadata-complete parameter above will improve application start times as well.

Mark Thomas is a Senior Software Engineer for the SpringSource Division of VMware, Inc. (NYSE: VMW). Mark has been using and developing Tomcat for over six years. He first got involved in the development of Tomcat when he needed better control over the SSL configuration than was available at the time. After fixing that first bug, he started working his way through the remaining Tomcat bugs and is still going. Along the way Mark has become a Tomcat committer and PMC member, volunteered to be the Tomcat 4 & 7 release manager, created the Tomcat security pages, become a member of the ASF and joined the Apache Security Committee. He also helps maintain the ASF's Bugzilla instances. Mark has a MEng in Electronic and Electrical Engineering from the University of Birmingham, United Kingdom.



shadow fight 2 apk mod So it is interesting and very good written and see what they think about other people. unlimited gems clash of clans

Hello there! This blog post

Hello there! This blog post could not be written any better! Reading through this post reminds me of my previous roommate! He continually kept preaching about this. I will forward this article to him. Pretty sure he'll have a very good read. Thanks for sharing!
Mortgage Broker Calgary

You have shared an

You have shared an informative post and I think it will be a great help for me. From this post I am able to understand the effective tips to use the fragments and annotations to configure my web application. Keep sharing such posts! hotel catalina

Annotations take this one

Annotations take this one phase further, and allow designers to annotate rule that dynamically configures program elements such as Servlets Check This Out and Filtration. Coffee collections and frameworks have been adopting annotations for a while. Actually, several IDE’s these times use annotations as a standard,


As i considered together your site because May possibly learned a lot of around ones own content articles. Lucky to imply, that gossip well spoken; you may be top notch during this. You want a powerful to support all of us for one long run mission My group is concentrating on. ed reverser review

I am happy to find this post

I am happy to find this post very useful for me, as it contains lot of information. I always prefer to read the quality content and this thing I found in you post. Thanks for sharing. metabolic cooking download rebelmouse

You have distributed an

You have distributed an useful publish and I think it will be a excellent help for me Continue. From this useful article I am able to comprehend the efficient suggestions to use the pieces and annotations to set up my web program. Keep discussing such posts! resort catalina

I personally use them

I personally use them exclusively high-quality elements : you will notice these folks during: more information

Both annotations and web

Both annotations and web items will impact performance, particularly recommended you read at system start-up. Tomcat has to examine out every classification in every jar pc computer file to recognize if the classification has been annotated as a Servlet, a Filter or Viewers.


The good news is solution you will come up with any blog which keep on coming back again. It’s fascination with this occupation benefit from any sayings to make sure you communicate the

One answer to make sure your

One answer to make sure your link pool that is energetic usually has contacts open to film making, every time a software is restarted, or it's to operate trash collection frequently.

I know that you explain it

I know that you explain it very well. And I hope that other readers will also experience how I feel after More Help reading your article. I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it. rebelmouse

I recently found many useful

I recently found many useful information in your website especially this blog page. Among the lots of comments on your articles. Thanks for sharing.

I really enjoy simply reading

I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post. Hats off to you! The information that you have provided is very helpful. red smoothie detox at

I personally use them

I personally use them exclusively high-quality elements : you will notice these folks during: fat grafting

Make the most of mainly

Make the most of mainly premium substances - you will find him or her for: Classic Shapes

I get pleasure from merely

I get pleasure from merely examining all your information sites. Merely needed to tell you you have people including everyone that get pleasure from your work. Surely a great article.

Profit primarily prime

Profit primarily prime quality items -- you can understand them all within: indoors and outdoors

I was very pleased to find

I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post. galaxy s7 edge manual

It's really nice and meanful.

It's really nice and meanful. it's really cool blog. Linking is very useful have really helped lots of people who visit blog and provide them usefull information.

I would recommend my profile

I would recommend my profile is important to me, I invite you to discuss this topic. Locksmith Richmond Indiana

I really appreciate this

I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people.

Regular visits listed here

Regular visits listed here are the easiest method to appreciate your energy, which is why why I am going to the website everyday, searching for new, interesting info. Many, thank you! powerpoint templates

Great post i must say and

Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more. the bonding code reviews

This post is really

This post is really magnificent. I really like this post. It is one of the best posts that I ve read in a long time. Thanks a lot for this really good post. I really appreciate it! HOW TO BUY PHYSICAL GOLD COINS ONLINE

Great post i must say and

Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.

This is exciting,

This is exciting, nevertheless it is vital for you to visit this specific url:

About Morkies - Morkie information

During this website, you will see this shape, i highly recommend you learn this review.
morkie puppies

One contact center

Why do only so much written on this subject? Here you see more.
call center Philippines


buy twitter followers I recommend only good and reliable information, so see it: twitter retweet

awsome It's its Incorporated

awsome It's its Incorporated web browser let you search Download iTube Android Office or another program while the backdrop is continued on by our download. iTube Download App Free nice.

Best E-Liquid & E Cigrates

I propose merely very good along with reputable data, consequently visualize it:
Doubler E Liquid Australia

good the program will likely

good the program will likely be set up successfully in your pc check official page you also may continue your chat. nice.

A+ Certification Practice Test PDF

I guide the students that how they can pass the exams and how can they get the certification for the latest knowledge this certification exam students click at exam or visit its certification its better for your bright future and will helpful to attain the Pass4sure 220-802 PDF

Aw, this was a very nice

Aw, this was a very nice post. Spending some time and actual effort to make a really good article… but what can I say… I procrastinate a whole lot and don't seem to get nearly anything done.
Edmonton Mortgage Broker
Life Insurance Vancouver
Life Insurance Calgary

awsome It's its Integrated

awsome It's its Integrated web web browser let you search Download iTube Android Office or another system while the history is ongoing on by our obtai click to find out more iTube Download App Totally free awesome. | Cheap Club Flyers | VIP Printing Services

Cheap Club Flyers Printing I am always searching online for storys that can accommodate me. There is obviously a multiple to understand about this. I feel you made few salubrious points in Attributes moreover. Detain busy, awesome career!

Muchos Beneficios de la Ortodoncia Invisible

With thanks for those helping blog you have really been making. I had shied off making feedback as news got around at this time. Clinica de Ortodoncia Invisible


There are several dissertation internet sites on-line because you get evidently reported as part of your web site.  miami to key west shuttle

Plantas Electricas

It is somewhat fantastic, and yet check out the advice at this treat.
Bogota Plantas Electricas

Post new comment

This question is for testing whether you are a human visitor and to prevent automated spam submissions.