This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Grokking Bitcoin and have Kalle Rosenbaum on-line!
See this thread for details.
Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

xml based vs annotation based  RSS feed

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wondering if spring supports a hybrid mix of xml based and annotation based code ? For example, if I define some <bean> in applicationContext.xml and define some other beans using annotation in their java class file, does Spring take that ?
 
Ranch Hand
Posts: 84
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can mix.
In Spring MVC, I have used an .xml config file, while annotating components with @Controller, @Service and @Repository.
 
Saloon Keeper
Posts: 20643
122
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spring, like Hibernate and I'm sure like several other platforms, started out using XML metadata files.

This was a real nuisance, since every time you touched something, there was a potential need to edit two files to do one task.

The introduction of annotations in Java 5 meant that the need for external definition of metadata was much reduced. However, the old XML forms have been kept for 2 reasons:

1. Backwards compatibility. Something that Java is expected to excel in.

2. Default/override mechanism. This allows you to define default meta-properties in the class source, but override them for specific instances. That means that you can wire in (re-use) objects with a minimum of external configuration, and it means that you can have multiple instances of the class where XML sets distinct properties for each instance. For example, the instance name.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now, new version suggests that, No XML based configuration. only java based annotations.
 
Tim Holloway
Saloon Keeper
Posts: 20643
122
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

vinoth sathi wrote:Now, new version suggests that, No XML based configuration. only java based annotations.



As I said in item 2, above, XML overrides annotations. Annotations are the preferred mechanism, but XML allows the flexibility to override annotations without making source code changes to the class. Or worse, having multiple instances where you'd otherwise have have to explicitly re-code the class for each case of different annotation values.
 
Bartender
Posts: 1010
18
IntelliJ IDE Java Linux Mac OS X Oracle Redhat Spring Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, horrid that XML.  Still useful when using spring integration as you can then use their STS diagram tool.

Never really sure when people say annotation configuration, as its my understanding that there are two types; Java configuration and component scanning - both use annotations.  Java config was the preferred way, so you still have the configuration in one central place, etc...
 
You didn't tell me he was so big. Unlike this tiny ad:
ScroogeXHTML - the small and fast RTF to HTML converter library
https://coderanch.com/t/707504/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!