在spring boot引用类路径资源的方式


1. 使用ClasspathResource

import org.springframework.core.io.ClassPathResource;
 
@Bean
public XsdSchema mySchema() {
return new SimpleXsdSchema(new ClassPathResource("myfile.xsd"));
}

2. 使用Resouce或配置:

import org.springframework.core.io.Resource;
 
@Value("classpath:myfile.xsd")
private Resource res;
 
@Bean
public XsdSchema mySchema() {
return new SimpleXsdSchema(res);
}