2 ways to refer classpath resource in spring boot projects

2 ways to refer classpath resource in spring boot projects

 

Using ClasspathResource

import org.springframework.core.io.ClassPathResource;

@Bean
public XsdSchema mySchema() {
return new SimpleXsdSchema(new ClassPathResource("myfile.xsd"));
}

 

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

Using Resource

import org.springframework.core.io.Resource;

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

@Bean
public XsdSchema mySchema() {
return new SimpleXsdSchema(res);
}

226 total views, 4 views today

About Mirthbees 672 Articles
Blogger, Innovator, Developer and Enterpreneur. Founder of GuruRecharge, Readymade online recharge script. Lead Developer in Bookrate.in

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.