TomcatExpert

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.

Comments

GAME HACK

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

Great write-up, I am a big

Great write-up, I am a big believer in commenting on blogs to inform the blog writers know that they’ve added something worthwhile to the world wide web!..
kizi2games.net

Robinjack

The ancient Egyptians valued silver because they considered it to be rare. They believed that the skin of the gods consisted of gold and their bones were made from silver. Similarly, in the ancient Aztec belief system, precious metals were said to have come from the gods. Gold represented excrement of the sun gods and silver was believed to be the excrement of the moon gods. This precious material was procured for the Spanish Empire by the conquistadors, which led to European commercial use of silver coins. In turn, the currency of the United States of America was based on the value of silver. Check Out Your URL

DANI

New web site is looking good. Thanks for the great effort.
read here

DANI

Your blog provided us with valuable information to work with. Each & every tips of your post are awesome. Thanks a lot for sharing. Keep blogging..
find more

Excellent information on your

Excellent information on your blog, thank you for taking the time to share with us. Amazing insight you have on this, it's nice to find a website that details so much information about different artists.
a course in miracles

This is such a great resource

This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It is the old what goes around comes around routine.
living miracles

DANI

Great content material and great layout. Your website deserves all of the positive feedback it’s been getting.
ucdm videos

DANI

Impressive web site, Distinguished feedback that I can tackle. I am moving forward and may apply to my current job as a pet sitter, which is very enjoyable, but I need to additional expand. Regards.
twitter

DANI

This is a great post. I like this topic.This site has lots of advantage.I found many interesting things from this site. It helps me in many ways.Thanks for posting this again.
go here

DANI

Its a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work.
Receitas

DANI

Hi there! Nice stuff, do keep me posted when you post again something like this!
smallbusiness ideas in india

DANI

An fascinating discussion is value comment. I think that it is best to write extra on this matter, it won’t be a taboo topic however generally people are not enough to talk on such topics. To the next. Cheers
currency converter

DANI

http://thekabultimes.gov.af/index.php/gallery/16650-war-and-violence-grabbed-all-education-opportunities-from-the-afghan-people-the-picture-shows-an-over-aged-man-attending-entrance-exam-process-of-university.html

DANI

Very good written article. It will be supportive to anyone who utilizes it, including me. Keep doing what you are doing – can’t wait to read more posts.
Kiev Tıp

This is such a great resource

This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It is the old what goes around comes around routine.
Kiev Müzik Akademisi

DANI

Its a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work.
bosna hersek üniversiteleri

I have read your blog it is

I have read your blog it is very helpful for me. I want to say thanks to you. I have bookmark your site for future updates.
outdoor sign stands

This is such a great resource

This is such a great resource that you are providing and you give it away for free.
evergreenpinecity.org

Your music is amazing. You

Your music is amazing. You have some very talented artists. I wish you the best of success.
Economics

This is such a great resource

This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It is the old what goes around comes around routine.
www.coonlightcove.com

This blog is so nice to me. I

This blog is so nice to me. I will keep on coming here again and again. Visit my link as well..
Montana ranches for sale

Its a great pleasure reading

Its a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work.
garage sales

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.
rent a water slide in Cincinnati

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,

David

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

This is a great post. I like

This is a great post. I like this topic.This site has lots of advantage.I found many interesting things from this site. It helps me in many ways.Thanks for posting this again.
read here

This is my first time i visit

This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles. I guess I am not the only one having all the enjoyment here! keep up the good work
http://www.floormarkingtape.co.uk/

Excellent .. Amazing .. I’ll

Excellent .. Amazing .. I’ll bookmark your blog and take the feeds also…I’m happy to find so many useful info here in the post, we need work out more techniques in this regard, thanks for sharing.
find here

This article gives the light in which we can observe the reality

This article gives the light in which we can observe the reality. This is very nice one and gives in depth information. Thanks for this nice article.
buy mobiles online

Great articles and great

Great articles and great layout. Your blog post deserves all of the positive feedback it’s been getting.
Mario n Sonic

I haven’t any word to

I haven’t any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us.
conga drum

Interesting post. I Have Been

Interesting post. I Have Been wondering about this issue, so thanks for posting. Pretty cool post.It 's really very nice and Useful post.Thanks
technology news and updates

I am very much pleased with

I am very much pleased with the contents you have mentioned. I wanted to thank you for this great article.
new upcoming gadgets

I have read a few of the

I have read a few of the articles on your website now, and I really like your style of blogging. I added it to my favorites blog site list and will be checking back soon. Please check out my site as well and let me know what you think.
pound to dkk

I am very enjoyed for this

I am very enjoyed for this blog. Its an informative topic. It help me very much to solve some problems. Its opportunity are so fantastic and working style so speedy.
Junk Removal Fairfax VA

I haven’t any word to

I haven’t any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us.
roof lanterns

as

Thanks for the post and great tips..even I also think that hard work is the most important aspect of getting success..
Scott Keever Cincinnati

this is really nice to

this is really nice to read..informative post is very good to read..thanks a lot!
Las Vegas Locksmith

Thank you so much for sharing

Thank you so much for sharing this great blog.Very inspiring and helpful too.Hope you continue to share more of your ideas.I will definitely love to read.
home security protection

DANI

I have been checking out a few of your stories and i can state pretty good stuff. I will definitely bookmark your blog
Büroeinrichtung

This is truly a great read

This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!.
website

Hello I am so delighted I

Hello I am so delighted I located your blog, I really located you by mistake, while I was watching on google for something else, Anyways I am here now and could just like to say thank for a tremendous post and a all round entertaining website. Please do keep up the great work.
translation services

DANI

Great post I would like to thank you for the efforts you have made in writing this interesting and knowledgeable article.
Mail Encryption

You have a good point here!I

You have a good point here!I totally agree with what you have said!!Thanks for sharing your views...hope more people will read this article!!!
bundapoker.net

Thanks for the nice blog. It

Thanks for the nice blog. It was very useful for me. I'm happy I found this blog. Thank you for sharing with us,I too always learn something new from your post.
cebu condos

Post new comment

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