簡體   English   中英

方法中的Java Spring Custom注釋

[英]Java Spring Custom annotation in method

我在春季啟動時遇到問題,帶有類注釋@Component和方法注釋@CustomAnnotation的bean未加載到SpringContext中

自定義注釋:

`@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)

請確認您已在spring配置文件中打開了組件掃描

它看起來應該像這樣:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM