我认为您所追求的是:
@Componentpublic class MyBean { private String xmlFile; private String xsdFile; @Autowired public MyBean(@Value("$MYDIR/myfile.xml") final String xmlFile, @Value("$MYDIR/myfile.xsd") final String xsdFile) { this.xmlFile = xmlFile; this.xsdFile = xsdFile; } //methods}您还可能希望通过系统属性来配置这些文件。您可以使用
@Value注释通过
PropertyPlaceholderConfigurer和
${}语法读取系统属性。为此,您可以
String在
@Value注释中使用不同的值:
@Value("${my.xml.file.property}")@Value("${my.xsd.file.property}")但您还将在系统属性中需要以下属性:
my.xml.file.property=$MYDIR/myfile.xmlmy.xsd.file.property=$MYDIR/myfile.xsd



