如何获得飞路豆

时间:2015-01-24 05:20:35

标签: java spring spring-boot flyway applicationcontext

Spring引导源中有一个类加载了飞路配置https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java

检查以下代码:

    @Bean(initMethod = "migrate")
    @ConfigurationProperties(prefix = "flyway")
    public Flyway flyway() {
        Flyway flyway = new Flyway();
        if (this.properties.isCreateDataSource()) {
            flyway.setDataSource(this.properties.getUrl(), this.properties.getUser(),
                    this.properties.getPassword(), this.properties.getInitSqls()
                            .toArray(new String[0]));
        }
        else if (this.flywayDataSource != null) {
            flyway.setDataSource(this.flywayDataSource);
        }
        else {
            flyway.setDataSource(this.dataSource);
        }
        return flyway;
    }

我需要Flyway类的实例。我的代码:

    ConfigurableApplicationContext ctx = SpringApplication.run(Application.class, args);
    Flyway flyway = ctx.getBean(Flyway.class);

失败了:

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.boot.maven.RunMojo$LaunchRunner.run(RunMojo.java:418)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.flywaydb.core.Flyway] is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:371)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:331)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:968)
at co.ambisafe.keyserver.Application.main(Application.java:14)
... 6 more

有谁知道这是什么问题?

0 个答案:

没有答案