spring-boot - 如何在spring中创建注释
问题描述
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Import({
testMethod.class
})
public @interface test{
public String value() default "";
}
@Component
public class testMethod{
...
}
在我的控制器中,我想使用我创建的注释
@test
@RequestMapping(...)
public response getAll(){
...}
我在testMethod中放了断点,它无法到达断点。似乎找不到 testMethod 组件。
解决方案
您需要导入一个配置类。如文档所述,@Import 注释用于导入配置,如下所示。
指示要导入的一个或多个 {@link Configuration @Configuration} 类。
public class TestBean {
public TestBean() {
}
}
@Configuration
public class TestMethod {
@Bean
public TestBean testBean() {
return new TestBean(); //put break-point here
}
}
推荐阅读
- python - 如何使用大约一小时的值重新采样熊猫系列
- amazon-web-services - AWS Lamba、多租户应用程序、独立数据库
- php - array_merge():将类添加到提供程序后,参数 #2 不是数组
- scala - 建立数据框
- python - Guttag教科书中的回文代码
- mysql - 我如何通过不同值的计数来获取值顺序
- c# - 如何使用if语句使用c#从sql server中检索一行数据
- python - 无论如何要使用 Python SDK 获取 azure Web 应用程序(Azure 函数应用程序)的 ftpsState 吗?
- swift - SwiftUI 中 NavigationBarTitle 中的额外间距
- google-cloud-firestore - Firestore REST API RunQuery 端点的教程有什么好的例子吗?