Announcement Announcement Module
Collapse

JavaConfig forum decommissioned in favor of Core Container

As described at

http://static.springsource.org/sprin...fig/README.TXT

key features of the Spring JavaConfig project have been migrated into the core Spring Framework as of version 3.0.

Please see the Spring 3.0 documentation on @Configuration and @Bean support:

http://static.springsource.org/sprin...tml#beans-java

For any questions related to @Configuration classes and @Bean methods in Spring 3.0, please post in the dedicated 'Core Container' forum at

http://forum.springsource.org/forumdisplay.php?f=26
See more
See less
how to compare java and xml config Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to compare java and xml config

    Hi All,

    I am trying to learn more about the options java config has to offer in comparison to xml config.

    I am currently looking on the petClinic application (the sample that is part of the java-config release) with the java-config , and I am trying to understand how it would look like in xml - does someone have the analogous xml version configuration of this application or any other "interesting" application with xml vs java configuration?

    Based on the comparison I saw in the web, I cant detect any special disadvantages of java-config, does someone have some insights regarding this?

    Thanks,
    Ora

  • #2
    For a comparison, you can take a look at the petclinic sample application that ships with spring itself. The JavaConfig petclinic app is simply a modified version of that original code.

    As for disadvantages in JavaConfig - the tooling with Spring IDE isn't as strong as it is for XML, there isn't perfectly equivalent support for high-level configuration with namespaces as there is in XML, and in some cases it's more verbose to create bean definitions in JavaConfig because you have to programmatically instantiate your beans (as opposed to declaratively in XML).

    With that said, it's not an either-or proposition. JavaConfig integrates seamlessly with XML config and vice-versa. Take a look at ConfigurationPostProcessor and @ImportXml to get a sense of what I mean.

    Comment


    • #3
      Thanks Chris,

      Can you elaborate a bit more about the differences in terms of the IDE support for java config and xml config.

      Also looking at the exmples of how to mix java&xml config in chapter 6, do you have somekind of rule-of-thumb of when it will be better to use xml config and when it will be better to use java-config and which methodology should be used to mix them?

      Thanks,
      Ora

      Comment


      • #4
        Regarding IDE support for JavaConfig, what I'm referring to is support by the Spring IDE for rendering bean graphs and other aids to development. Spring IDE delivered some basic integration for JavaConfig a while back, but this support is largely out of date today. This will be updated in the future (probably post-JavaConfig-1.0), but in the meantime, keep in mind that JavaConfig does not need nearly as much customized support as XML! Because it's pure Java, your IDE is all you really need.

        As for rules of thumb with XML vs JavaConfig, if you're using the higher-level namespace support (like jms: for example), you'll be best off keeping that stuff in XML (JavaConfig doesn't have 1:1 support for all the namespaces in XML). Other than that, it's a personal preference thing. If you'd like to keep close to everything in plain Java, go for it. As for integrating the two, I often prefer to keep JavaConfig as the bootstrapping mechanism (using JavaConfigApplicationContext or JavaConfigWebApplicationContext as appropriate) and then pulling in XML with @ImportXml as necessary. This gives a Java-centric view of configuration in your application, as opposed to bootstrapping via XML and pulling in JavaConfig via ConfigurationPostProcessor.

        Really, there's no one 'right way' to do this. I would play around with both and see what suits your preferences / needs.

        Comment


        • #5
          hi,

          I just try to play around with javaConfig (1.0.0.M4) with spring (spring 3.0 RC 1).

          then I stuck in the error which look like this http://forum.springsource.org/showthread.php?t=74730

          anyway, I had some question.

          1) Will javaConfig initialize faster then in xml ? i can;t try out cause I stuck in the error, is anyone doing comparison before ?

          2) will JavaConfig support name space eventually ? (spring batch is full of namespace, and code every batch in xml is hard to see by human eye).

          after try to convert my 6 spring xml file to 6 *Config.java (which is 1 to 1 equivalent) I find that the javaConf not make the code small (surpise ), and in some case it since like xml is easy (yeah.. when u doing configuration on external resource, like API key for external service, etc).

          kiwi
          ----
          happy hacking

          Comment

          Working...
          X