我尝试使用 @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
已正确注入(inject)并保存一个值,例如testProperty.name =“Bean1”
目前我创建的 Bean 仅以 EL 表达式作为名称:{"bean":"#{testProperty.name}"
如何从 testProperty.name
中为 MyBean
提供其名称?
最佳答案
您可以使用 @Scheduled
注释的 cron
属性的属性值:
@Scheduled(cron = "${testProperty.name}")
所以根本不需要 SpEL。
关于java - 使用 @Bean 注释和 Spring EL 表达式创建 Bean 和名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41054923/