我收到以下错误:
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");
}
最佳答案
在此构造函数中:
public NewCCtx(Environment inputProperties) {
this.productName = inputProperties.getProperty("product.name");
}
您应该使用正确的参数显式调用 super 构造函数 (CommonCtx
):
public NewCCtx(Environment inputProperties) {
super(inputProperties);
this.productName = inputProperties.getProperty("product.name");
}
这是必需的,因为您的父类没有零参数构造函数。
关于Java-spring错误: Actual and formal argument differ in length,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33518021/