This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming 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
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

xml based vs annotation based

 
Greenhorn
Posts: 28
  • 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: 87
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: 21122
131
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • 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: 26
  • 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: 21122
131
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • 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: 1040
18
Mac OS X IntelliJ IDE Oracle Spring VI Editor Tomcat Server Redhat Java Linux
  • 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...
 
I can't take it! You are too smart for me! Here is the tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!