DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Graceful Shutdown: Spring Framework vs Golang Web Services
  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4
  • Implementing Exponential Backoff With Spring Retry
  • Structured Logging in Spring Boot 3.4 for Improved Logs

Trending

  • You Do Not Need a PhD to Become an AI Engineer: The Essential Skill Stack
  • Kafka vs Flink vs Spark: Do You Really Need Real-Time?
  • Agent Harness, Memory Indexing, and AI Governance in Test Automation
  • How to Hide Sensitive Information Before You Share a File

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Frameworks
  4. Spring Framework – XML vs. Annotations

Spring Framework – XML vs. Annotations

Some rules of thumb on when to use either XML or annotation based configurations

By 
Kapil Viren Ahuja
·
Aug. 07, 15 · Opinion
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
39.6K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

This question has been around for many years since Spring started to move heavily towards Annotation based configurations (if I recall, it’s called configuration by convention). Annotations based configurations were like a jungle fire that spread across the industry and very soon it was the norm. But, this question “XML vs. Annotations” always existed.

I for one have been around the Spring world since version 1.1 when annotations weren’t a thing. I know how write XML and I know how to configure an application to suit my needs. Since then, whenever I write an application in Spring, I have asked myself "XML or Annotations" and I never really had a good answer until recently. While you will find tons of posts around this topic in Google,  when you search for this, only a few really give you an unbiased opinion.

I started to work on an application that needs some very flexible configuration options and before I dive into that I had to make this decision yet again, and this time I wanted to keep things simple and my rationale was…

  • Use Annotations in anything that is stable and defines the core structure of the application. Anything that would need a code change is okay to sit as an annotation.

Use XML based configurations when you know you may have a need to alter the behavior of an application without the need of compiling and deploying the code all over again.

This is how simple I kept it for my team. Once this principle is defined, job is only halve done. But we will get there soon.

Spring Framework XML Annotation Framework

Published at DZone with permission of Kapil Viren Ahuja. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Graceful Shutdown: Spring Framework vs Golang Web Services
  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4
  • Implementing Exponential Backoff With Spring Retry
  • Structured Logging in Spring Boot 3.4 for Improved Logs

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook