Spring is giving me below error, but can't figure out why is it !
春天给了我下面的错误,却想不出为什么!
Note: There is no bean definition in xml file for this.
注意:在XML文件中没有对此的Bean定义。
Bean named 'resetDatabase' is expected to be of type
'java.lang.Runnable' but was actually of type
'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();
}
}
I referred this as well but couldn't find any solution for my case
我也提出了这一点,但没有为我的案件找到任何解决方案
更多回答
What is the type of the Object returned by resetDatabase_H2();
and resetDatabase_Postgresql();
设置数据库_H2();和设置数据库_PostgreSQL()返回的对象类型是什么;
@KarthikeyanVaithilingam Runnable. However resetDatabase_Postgresql always returns null.
@KarthikeyanVaithilingam Runnable。但是,setDatabase_postgreSQL总是返回NULL。
Then you have to investigate why ` resetDatabase_Postgresql` is returning null.
那么您需要调查一下为什么`setDatabase_Postgresql`返回NULL。
优秀答案推荐
If resetDatabase_Postgresql
can return null
, then you can wrap it into an optional and return a runnable that does nothing in that case:
如果ResetDatabase_PostgreSQL可以返回NULL,则可以将其包装在可选变量中,并返回在这种情况下不执行任何操作的Runnable:
return Optional.ofNullable(resetDatabase_Postgresql()).orElse(() -> {});
更多回答
我是一名优秀的程序员,十分优秀!