0

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)

David Welch
  • 1,941
  • 3
  • 26
  • 34

2 Answers2

1

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.

Stephane Nicoll
  • 31,977
  • 9
  • 97
  • 89
  • Appreciate the response. Hard to carve out the details without the entire app, but essentially in the main method I check for a few args and, if present, run this alternate app instead. However, spring web / data / etc all auto load from that single run statement (in addaition to all my @Controller classes and such). Don't the spring.factories and such get loaded and processsed automatically? – David Welch Oct 15 '16 at 22:46
  • I already answered to that in my reply (no, unless you have `@EnableAutoConfiguration` which you don't in your example). I can't help you with the details you are sharing, sorry. – Stephane Nicoll Oct 17 '16 at 10:37
0

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.

Community
  • 1
  • 1
luboskrnac
  • 23,973
  • 10
  • 81
  • 92