Alex Worden
Alex Worden

Reputation: 3415

How to import xml files in Spring Boot?

I'm porting a Spring application to Spring Boot. I'd like to be able to configure Spring Security using xml so I can use my old config files. (I've tried using Java config and it doesn't work).

How do I get Spring Boot to pick up the xml configuration? Spring does not see to have any documentation on this.

Upvotes: 0

Views: 9901

Answers (3)

hudi
hudi

Reputation: 16555

Why do you want to import your old xml file ? The best thing about spring-boot is that you don't need to use your old file and you can rewrite it in java

Upvotes: 0

Anish B.
Anish B.

Reputation: 16589

You have to use @ImportResource.

@SpringBootApplication
@ImportResource("classpath:<name>.xml")
public class Config {
   public static void main(String[] args) {
      SpringApplication.run(Config.class, args);
   }  
}

Refer to these links for proper understanding :

  1. @ImportResource - Java Docs
  2. A well defined example on @ImportResource

Upvotes: 3

seenukarthi
seenukarthi

Reputation: 8682

You can import xml configuration using org.springframework.context.annotation.ImportResource annotation. in one of the configuration class which is annotated with @Configuration do the following.

If your security config is named security-config.xml at the root of the classpath then add the like below.

@ImportResource({"classpath:security-config.xml"})

Upvotes: 2

Related Questions