Aug 8th, 2011, 01:29 PM
Generate beans definition XML from annotations?
I have an existing Spring application configured with annotations (@Serive, @Autowired, etc.). The XML configuration uses <context:component-scan /> and <context:annotation-config /> to load the application's bean definitions.
Is there a tool that can export this annotation configuration in the XML format? This could be an Ant task, IDE plug-in, or most anything else. I've considered doing the work manually too, but having an automated tool would be quite helpful.
Aug 14th, 2011, 07:12 AM
No there isn't AFAIK... And why would you want it?
Aug 15th, 2011, 10:31 AM
I have a corner case scenario where I'm starting a Spring ApplicationContext inside of a JPPF task (http://www.jppf.org/) and the annotation component scan isn't working due to the JPPF environment limitations. However, my normal run scenario is Tomcat 7 and the annotations obviously work fine there. I was hoping to either always generate the XML configuration from my current annotation configuration, or generate it once to then maintain it (and remove my annotations).
I wrote a crude annotation processor that creates the <bean> XML configuration for use in my JPPF task. I can then use my existing <context:annotation-config /> to autowire the beans.
Aug 15th, 2011, 01:41 PM
I don't know the framework but you shouldn't instantiate a new application context each time you need one... You should create a single one and reuse that throughout your program execution.
Aug 15th, 2011, 02:50 PM
JPPF is a parallelization framework that allows you to perform Java tasks on remote hosts in a cluster. In my case, I'm attempting to execute my Spring application on a remote host. So I cannot share the same context instance across hosts and have to create a new one.