2

I need some adivce. I am creating new application in spring 4 and wonder which configuration is better. For spring 4 brings conditional bean configuration for java config. Can you tell me which configuration you would chose and why? Is there something what i can't do in java config but can in xml and vice versa? I know that xml config allow me to change config without recompile is there something else?

John
  • 363
  • 2
  • 6
  • 19
  • "Changing config without recompile" is a very ambiguous feature, did it change immediately, did you have to stop/start the app? There shouldn't be any correlation between the format of the config and when changes are applied, it's the matter of the component that parse/detect changes – gerrytan Nov 06 '14 at 22:05
  • No, it doesn't change immediately, i need to stop and then start app. – John Nov 06 '14 at 22:13

2 Answers2

0

Please check out this question of XML vs Config:

Xml configuration versus Annotation based configuration

As you can see they cover in depth as to XML vs Config that will help you choose what is the best fit for your project.

Community
  • 1
  • 1
Aeseir
  • 7,754
  • 10
  • 58
  • 107
  • I saw it, but that answers are old(2008). Spring 3 was released in 2009, spring 4 2013/2014. So it's doesn't have view on features which Spring 4 brings now. – John Nov 06 '14 at 22:36
  • The answer is still valid tho. This is more architectural framkework question rather than anything. If the question is "what should i use for my project xml or config" in that case you would need to list all the functions/features you wish to utilise, then see the difference between XML and Config. Based on that make the appropriate choice. Spring Projects change, and a lot have moved to Java Config from XML. I hope that makes sense. – Aeseir Nov 06 '14 at 22:40
0

You have three ways to declare your beans

  1. XML (the classic, first option from the beginning)
  2. Annotations (@Service, @Repository, @Controllers)
  3. JavaConfig working together with @Configuration and @Bean

My suggestion

One:

For Infrastructure Beans such as: DataBase configuration, JDBC Configuration, Hibernate/JPA Configuration, Transaction Configuration and more use JavaConfig, it is very flexible about type safe and refactoring

Two:

For your own services, repositories, controllers use Annotations such as @Service, @Repository, @Controllers, with them, you are able to work together with @Autowired and if is necessary with @Qualifier.

Three:

Is legal work around with XML, but if you read the latest Blog's post from Spring.io, many of them are working with Annotations and JavaConfig. It because both approaches are working with Java.

Manuel Jordan
  • 15,253
  • 21
  • 95
  • 158