IoC Container - ResourceLoader
- 📚 Spring/Spring 개념
- 2020. 9. 11. 16:55
| ResourceLoader
- Applicationcontext가 상속받고 있다.
- 리소스를 읽어오는 기능을 담당하는 인터페이스 이다.
예제
- resources폴더에 test.txt 파일을 생성한다.
@Component
public class AppRunner implements ApplicationRunner {
@Autowired
ResourceLoader resourceLoader;
// ApplicationContext 해도 동일하다. why? applicationContext가 ResourLoader를 상속받고 있으니까
@Override
public void run(ApplicationArguments args) throws Exception {
Resource resource = resourceLoader.getResource("classpath:test.txt");
System.out.println(resource.exists());
System.out.println(resource.getDescription());
System.out.println();
}
}
결과
true
class path resource [test.txt]
경로에 해당 파일이 존재히여 true가 나왔다.
ClassPath
-
classpath는 앱이 실행 된 후 실제로 리소스가 저장되는 위치를 말한다.
-
별도의 설정을 하지 않았다면 프로젝트 내부에 target이라는 폴더가 생성되는 데 target/classes 하위에 위치해 있다.
'📚 Spring > Spring 개념' 카테고리의 다른 글
데이터 바인딩 추상화 : PropertyEditor (0) | 2020.09.14 |
---|---|
Resource 추상화 (0) | 2020.09.14 |
IoC Container - ApplicationEventPublisher (0) | 2020.09.11 |
IoC Container - MessageSource (0) | 2020.09.11 |
IoC 컨테이너 - Environment (0) | 2020.09.09 |