32

I'm using spring-boot and would like to automatically import src/main/resources/applicationContext.xml file.

So far it only works if I explicit tell spring to import it:

@EnableAutoConfiguration
@Configuration
@ImportResource({"classpath*:applicationContext.xml"})

But spring-boot has so many default, maybe someone knows the "default" name for the app.xml file so that is gets picked up by spring-boot by default?

membersound
  • 81,582
  • 193
  • 585
  • 1,120
  • is it part of a web-application? – Braj Sep 05 '14 at 14:13
  • If it's a part of web application then you can use default name to load spring application context. If the name of `servlet-name` is `xyz` for `DispatcherServlet` in `web.xml` then it will load `xyz-servlet.xml` file automatically from class-path where you can import other spring configuration files using `` – Braj Sep 05 '14 at 14:24
  • It's a simple webapplication that should host a single SOAP webservice. So I have no explicit servlet name. The soap is wired by cxf. – membersound Sep 05 '14 at 14:34

1 Answers1

23

There is no such feature for importing an XML configuration by default based on it's name or location.

Check out this part of the documentation.

geoand
  • 60,071
  • 24
  • 172
  • 190
  • Correct. However, spring boot application can be used to import .properties (.yml) files automatically from classpath as a part of @EnableAutoConfiguration module. – Abhishek Shah Nov 24 '17 at 05:43
  • @AbhishekShah That is true and is meant to include configuration properties. What OP is asking is whether or not a way Spring Boot would automatically import any specific XML files that define Spring beans – geoand Nov 24 '17 at 08:43
  • 1
    Agreed. Apologized for misunderstood. There no such kind of feature for auto import XML file for spring beans. You must have to specify it in your configuration class. – Abhishek Shah Nov 24 '17 at 09:18
  • Link is dead 123 – Elie G. Dec 09 '18 at 22:04
  • Thanks @DrunkenPoney, fixed now – geoand Dec 10 '18 at 10:13