0

I am trying to migrate our application from Spring XML based configuration to annotation based configuration. In one of our XML files, say application-config.xml, we have the following line:

<import resource="${jobName}/beans.xml" />

Here ${jobName} is a System property which is set at JVM startup. There are additional system properties that are used to load additional XML resources. Now in my annotation based configuration, I want to have similar @Configuration classes as the XML files themselves. Hence I have a class ApplicationConfig that will import the jobName specific Configuration class.

How do I achieve this?

@Configuration
@Import({somehow-need-to-use-system-property-to-import-appropriate-class})
class ApplicationConfiguration {
    //bean definitions
}
Swaranga Sarma
  • 13,055
  • 19
  • 60
  • 93

1 Answers1

-1

@Import is used to import other Configuration classes into the spring context.

Use @ImportResource to import an xml file.

Since spring 3.1 spring supports system properties in @Import.

I did not check for @ImportResource, but it should be possible as well.

  • I don't want to keep any of my XML files. What I want is to migrate all my beans into annotation configurations and import them in the same way as I currently do. – Swaranga Sarma May 22 '16 at 20:03