【发布时间】:2020-02-19 18:33:50
【问题描述】:
我有这样的代码。
@org.springframework.stereotype.Component("studentInfo")
@org.springframework.context.annotation.Profile("studentInfo")
public class CustomStudentInfo{
如您所见,我有组件名称和相同的配置文件,我的意思是我只想在设置配置文件时才将此类设置为 bean,而且事实上这是有效的,但在 2 行上键入它有点烦人我的问题是我可以在自定义注释上使用它吗?我的意思是帮助我写作的注释。
@CustomSpringAnnotation("studentInfo")
public class CustomStudentInfo{
如果问题很简单,谢谢和抱歉。
【问题讨论】:
-
在引入自定义注释时,我看到的障碍是,您不能将自定义注释的
value("studentInfo") 传递给 @Profile/@Component...与“base类”,您只能使用“常量表达式”(也可以是(静态)最终字段) -
嗨,谢谢你能提供一些例子
标签: spring ioc-container