如何在春季创建注释

时间:2019-12-10 01:36:17

标签: spring-boot

@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组件。

1 个答案:

答案 0 :(得分:0)

您需要导入Configuration类。如记录所示,@ Import批注用于导入配置,如下所示。

  

指示要导入的一个或多个{@link Configuration @Configuration}类。

public class TestBean {
    public TestBean() {
    }
}

@Configuration
public class TestMethod {
    @Bean
    public TestBean testBean() {
        return new TestBean(); //put break-point here
    }
}