Announcement Announcement Module
No announcement yet.
Check some Spring potential errors on buildtime, not only on runtime Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Check some Spring potential errors on buildtime, not only on runtime

    I like Spring but I can't check some errors on buildtime.

    For example :

    I write sommething like

    Datasource datasource = (Datasource) factory.getBean("datasource");

    If datasource doesn't exist in applicationContext.xml or the type of the class is not Datasource, we can't see that on buildtime but only on runtime.

    Is it possible to check on buildtime this kind of errors?

  • #2
    Don't use factory.getBean() at all, and use local= in your xml to refer to dependencies. It isn't a complete solution in all situations (e.g. the bean references have to be local - in the same xml file), but it is the only way I know to do dependency checking without starting Spring.

    Also checkout the new ideas on Java configuration in Rod's blog ( The project is not released into core Spring yet, but it may well be the perfect answer to your question when it is.


    • #3
      When I wrote

      Datasource datasource = (Datasource) factory.getBean("datasource");

      I thought the interaction between your java code and your xml files, not ontly th e dependencies inside your xml files.

      Concerning your article, I read it one or two month ago and I didn't realise this bean configuration allow to check errors on buildtime or to refactor your code. The configuration seems a quite strange at the beginning but so powerfull compared to xml configuration.