我尝试使用@Bean(value="")
属性创建一个 Bean 及其名称。value
应使用Spring EL Expression
进行设置。
@Configuration
public class TestClass{
@Autowired
TestProperty testProperty
@Bean(value="#{testProperty.name}")
public MyBean myBean(){
MyBean b = new MyBean();
return b;
}
}
我的testProperty
正确注入并保存一个值,例如testProperty.name = "Bean1"
目前,我创建的 Bean 仅将 EL 表达式作为其名称:{"bean":"#{testProperty.name}"
我怎样才能从testProperty.name
给MyBean
起名字?
您可以将属性值用于@Scheduled
注释的cron
属性:
@Scheduled(cron = "${testProperty.name}")
所以根本不需要SpEL。