2015-11-04 3 views
0

Я получаю следующее сообщение об ошибке:ошибка Java-весна: Фактические и формальный аргумент различаются по длине

Error:constructor Commonctx in class CommonCtx cant be applied to given types; required: org.springframework.core.env.Environment found:no arguments reason: actual and formal argument lists differ in length.

код который используется:

@Component 
@PropertySource("file:${input.file.loc}") 
public class CommonCtx implements IContext { 

    private String tempDir; 

    @Autowired 
    public CommonCtx(Environment inputProperties) { 

     tempDir = inputProperties.getProperty("temp.dir"); 
... 
} 

@Component 
@Conditional(cond1.class) 
@PropertySource("file:${input.file.loc}") 
public class NewCCtx extends CommonCtx implements NewCContext{ 

    private String productName; 

    /** 
    * @param inputProperties 
    */ 
    @Autowired 
    public NewCCtx(Environment inputProperties) { 
     this.productName = inputProperties.getProperty("product.name"); 
    } 

ответ

1

В этом конструкторе:

public NewCCtx(Environment inputProperties) { 
    this.productName = inputProperties.getProperty("product.name"); 
} 

Вы должны явно называть супер конструктор (CommonCtx) с его правильным аргументом:

public NewCCtx(Environment inputProperties) { 
    super(inputProperties); 
    this.productName = inputProperties.getProperty("product.name"); 
} 

Это необходимо из-за того, что родительский класс не имеет конструктора с нулевым аргументом.

+0

Большое спасибо за помощь! – user1731553

+0

Добро пожаловать, рад помочь. :) –

Смежные вопросы