我试图用以下方式实例化一个Spring bean:
<bean id="myParser class="com.parser.MyParser">
<constructor-arg type="java.io.InputStream"
value="classpath:regex.yaml" />
</bean>
MyParser定义了以下构造函数:
public MyParser() throws IOException {
this(MyParser.class.getResourceAsStream(DEFAULT_YAML_PATH));
}
public MyParser(InputStream regexYaml) {
initialize(regexYaml);
}
但是在运行时,我收到一个错误,无法创建bean,因为找不到匹配的构造函数:
Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
发现错误,显然,如果文件不在类路径上,那么InputStream不能被实例化,它将导致上面的错误