0

I am developing an application that runs on Spring Boot configured via XML. For modularity, I didn't want to use @ImportResource as it requires me to go into the source code when in XML configuration I can just configure the XML files to change dependencies.

The problem is that I'm using Spring Boot to run my Spring MVC Controllers (@Controller) and for me to make use of the dependencies I configured in my XML files, I need to declare @ImportResource, which I don't want to use.

Is there any workaround to not use @ImportResource while still using XML config files to inject the dependencies in my Spring MVC Controllers?

  • Hint: `@ImportResource` can also take a pattern/wildcards... Also has nothing to do with XML or Java you could achieve the same with Java based configuration. – M. Deinum May 30 '18 at 06:52

1 Answers1

1

If you are using spring boot and you are ok with mentioning the config location in application properties, you can do this in application.properties

config:
  location: file:///config.xml

And the you can use this property in your @ImportResource

@ImportResource("${config.location}")

This way you can avoid changes to the source code, while still using xml configuration.

raiyan
  • 821
  • 6
  • 15
  • This seems alright. How do I do this with multiple locations? – Carlo Miras May 30 '18 at 14:49
  • `config.location[0]: location1`,`config.location[1]: location2`. Maybe this would help: https://stackoverflow.com/a/46185767/5189158 – raiyan May 30 '18 at 15:50
  • I'm sorry but the @ImportResource doesn't recognize the different config.locations I set. – Carlo Miras May 31 '18 at 01:46
  • Nevermind. What I did was that I just used one XML config file where all the other config files could be loaded to. But thank you still! [https://stackoverflow.com/questions/5113579/how-to-import-spring-config-xml-of-one-project-into-spring-config-xml-of-another] – Carlo Miras May 31 '18 at 08:40