2 ways to refer classpath resource in spring boot projects

2 ways to refer classpath resource in spring boot projects

 

Using ClasspathResource

[java]
import org.springframework.core.io.ClassPathResource;

@Bean
public XsdSchema mySchema() {
return new SimpleXsdSchema(new ClassPathResource(“myfile.xsd”));
}
[/java]

 

Note: Here myfile.xsd should be located in src/main/resources.

Using Resource

[java]
import org.springframework.core.io.Resource;

@Value(“classpath:myfile.xsd”)
private Resource res;

@Bean
public XsdSchema mySchema() {
return new SimpleXsdSchema(res);
}
[/java]

Leave a Reply