David Welch
David Welch

Reputation: 1991

Programmatically configure Spring Boot app

what's the easiest way to get the spring boot goodness but not try to autoconfigure all the things? For instance, to only run flyway with our already configured properties (some loaded via Consul + Spring Cloud), I was hoping I could do something like:

@Configuration
@Import({DataSourceAutoConfiguration.class, FlywayAutoConfiguration.class})
public class FlywaySetup {}

and have the main method just call SpringApplication.run(FlywaySetup.class)

The problem with this is it picks up all the Component Scan / crazy long list of other dependencies. Any way to specifically configure the dependencies (but still get the nicities of the framework)

Upvotes: 0

Views: 950

Answers (2)

Stephane Nicoll
Stephane Nicoll

Reputation: 33121

If you run this app, it shouldn't use component scan at all. There's nothing that triggers component scan in spring boot besides @ComponentScan (that's available on @SpringBootApplication).

It would help if you could provide more accurate details rather than "crazy long list of other dependencies.". Running that FlywaySetup should only load those two configuration classes (important: these are not handled as auto-configuration anymore). If you have component scan, there's something else you're not showing.

Upvotes: 1

luboskrnac
luboskrnac

Reputation: 24571

You can exclude auto-configurations you don't need.

You may want to take a look at this SO answer to explore mechanism how to do that.

Upvotes: 0

Related Questions