Giriş
Şu satırı dahil ederiz.
Örnek
Şöyle yaparız.
Şu satırı dahil ederiz.
import org.springframework.context.ResourceLoaderAware;
setResourceLoader metoduÖrnek
Şöyle yaparız.
@Component
public class StartupHousekeeper implements ResourceLoaderAware {
private ResourceLoader resourceLoader;
@EventListener(ContextRefreshedEvent.class)
public void contextRefreshedEvent() {
try {
// Read file from src/main/resources folder
File sourceFile = new File(getClass().getClassLoader()
.getResource("app_dev.json").getFile());
// Read file from src/main/webapp folder
Resource resource = resourceLoader.getResource("file:webapp/AppConfig.json");
File file= resource.getFile();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void setResourceLoader(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}
}
Hiç yorum yok:
Yorum Gönder