tig*_*g3n 0 java spring annotations
我有一个配置文件,我想根据配置文件创建不同的bean.
出于某种原因,这是有效的:
@Configuration
@Profile("myProfile")
public class myClass {
Run Code Online (Sandbox Code Playgroud)
这不是,在Eclipse中给出错误消息:
@Profile
此位置不允许使用注释
@Bean
@Profile("myProfile")
Run Code Online (Sandbox Code Playgroud)
我宁愿使用第二个,但我不确定我是否可以.Spring API说它应该工作:
该
@Profile
注释可以在以下任一方式使用:
- 作为直接或间接注释的任何类的类型级注释
@Component
,包括@Configuration
类- 作为元注释,用于组成自定义构造型注释
- 作为任何@Bean方法的方法级注释
我正在使用Sping Framework 3.1.0,是否有可能@Bean
仅在使用on 方法之后?
归档时间: |
|
查看次数: |
2086 次 |
最近记录: |