loyalflow
loyalflow

Reputation: 14879

Storing spring configuration in a class versus xml file

Currently my spring configurations are in a xml file (the traditionaly way).

One thing that i like about this is during deployment I can deploy a different version that has my production settings, or say in a test environment I can have test settings there.

I like the idea of having things configured in a class, but that will get compiled into my war and then it won't be as flexible.

Is there a way around this?

Upvotes: 2

Views: 567

Answers (3)

Guido Simone
Guido Simone

Reputation: 7952

The spring reference manual includes a section on combining both Java and XML configuration. See http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/beans.html#beans-java-combining

If you tend to be more XML centric you can bootstrap your app using XML and then introduce Java config as needed in an ad-hoc fashion. This might be a good way to ease into it. You might decide to go Java config all the way.

Upvotes: 0

Tomasz Nurkiewicz
Tomasz Nurkiewicz

Reputation: 340693

Java configuration is great and it has several advantages:

  • refactoring-friendly

  • type-safety

  • much more flexible (you can write any Java code, not being bound to XML semantics and capabilities).

I can deploy a different version that has my production settings, or say in a test environment I can have test settings there.

Investigate Spring @Profiles. They are orthogonal to your question (work both in XML and @Configuration) but are best suited in your situation.

Upvotes: 4

kosa
kosa

Reputation: 66637

Those are the only two ways available. If you don't want configuration baked in code, then you have to go with xml.

Upvotes: 0

Related Questions