方法中的Java Spring Custom注释

时间:2014-02-21 19:02:48

标签: java spring spring-annotations

我在spring启动时遇到问题,在SpringContext中没有加载带有类注释@Component和方法注释@CustomAnnotation的bean

自定义注释:

`@Target(value = { ElementType.METHOD })
@Retention(value = RetentionPolicy.RUNTIME)
public @interface ExcecuteRuleSet {
    String[] ruleSetName();
    boolean onErrorStopProcess() default false;
}`

类:

@Component
public class VehicleTypeBean implements GenericBean {

@Override @ExcecuteRuleSet(ruleSetName="rules")
public VehicleType convertToModelObject(DESRequest request) throws ServerException {
        return this.communicatorConverterService.convertToModelObject(request.getPayload(VehicleTypeRequest.class));
    }
}
`

错误:

SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [coop.tecso.bean.VehicleTypeBean] is defined
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:296)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1125)
    at coop.tecso.spring.AppContextService.getCustomBean(AppContextService.java:27)

1 个答案:

答案 0 :(得分:0)

请确认您已在弹簧配置文件中打开component scanning

看起来应该是这样的:

<context:component-scan base-package="coop.tecso"/>