名为X的Bean应该是"java.lang.Runnable"类型,但实际上是"org.springframework.beans.factory.support.NullBean"的类型。



Spring在下面给我带来了错误,但无法弄清楚为什么会这样!

注意:XML文件中没有bean定义。

bean名为" resetdatabase"的豆类预计为类型 'java.lang.runnable',但实际上是类型 'org.springframework.beans.factory.support.nullbean'

@Bean
Runnable resetDatabase() throws Exception
{
    if (env.acceptsProfiles("prof"))
    {
        return resetDatabase_H2();
    }
    else
    {
        // return resetDatabase_H2();
        return resetDatabase_Postgresql();
    }
}

我也提到了这一点,但找不到任何解决方案

如果resetDatabase_Postgresql可以返回null,则可以将其包装到可选的情况下并返回可运行的可在这种情况下无能为力的可运行:

return Optional.ofNullable(resetDatabase_Postgresql()).orElse(() -> {});

相关内容

最新更新