githubEdit

Spring Resource

java.net.URL의 ν•œκ³„λ₯Ό (classpath λ‚΄λΆ€ μ ‘κ·Όμ΄λ‚˜ μƒλŒ€κ²½λ‘œ λ“±) λ„˜μ–΄μ„œκΈ° μœ„ν•΄ μŠ€ν”„λ§μ—μ„œ μΆ”κ°€λ‘œ κ΅¬ν˜„

Resource Interface와 κ·Έ κ΅¬ν˜„μ²΄λ“€

public interface Resource extends InputStreamSource {

    boolean exists();

    boolean isReadable();

    boolean isOpen();

    boolean isFile();

    URL getURL() throws IOException;

    URI getURI() throws IOException;

    File getFile() throws IOException;

    ReadableByteChannel readableChannel() throws IOException;

    long contentLength() throws IOException;

    long lastModified() throws IOException;

    Resource createRelative(String relativePath) throws IOException;

    String getFilename();

    String getDescription();
}

Resource κ΅¬ν˜„μ²΄ λͺ©λ‘

Spring λ‚΄λΆ€ Resource κ΅¬ν˜„μ²΄ 쀑 λŒ€ν‘œμ μΈ λͺ‡κ°€μ§€

UrlResource

java.net.URL 을 λž˜ν•‘ν•œ 버전, λ‹€μ–‘ν•œ μ’…λ₯˜μ˜ Resource 에 μ ‘κ·Ό κ°€λŠ₯ν•˜μ§€λ§Œ κΈ°λ³Έμ μœΌλ‘œλŠ” http(s) 둜 원격 μ ‘κ·Ό (ftp:, file:, http:, λ“±μ˜ prefix 둜 μ ‘κ·Όμœ ν˜• νŒλ‹¨)

ClassPathResource

classpath ν•˜μœ„μ˜ λ¦¬μ†ŒμŠ€ μ ‘κ·Ό μ‹œ μ‚¬μš© (μ†ŒμŠ€μ½”λ“œλ₯Ό λΉŒλ“œν•œ κ²°κ³Ό(기본적으둜 target/classes 폴더))

FileSystemResource

File 을 닀루기 μœ„ν•œ λ¦¬μ†ŒμŠ€ κ΅¬ν˜„μ²΄

SevletContextResource, InputStreamResource, ByteArrayResource

Servlet μ–΄ν”Œλ¦¬μΌ€μ΄μ…˜ 루트 ν•˜μœ„ 파일, InputStream, ByteArrayInput μŠ€νŠΈλ¦Όμ„ κ°€μ Έμ˜€κΈ° μœ„ν•œ κ΅¬ν˜„μ²΄

Spring ResourceLoader

μŠ€ν”„λ§ ν”„λ‘œμ νŠΈ λ‚΄ Resource 에 μ ‘κ·Όν•  λ•Œ μ‚¬μš©ν•˜λŠ” κΈ°λŠ₯

  • 기본적으둜 applicationContext μ—μ„œ κ΅¬ν˜„μ΄ λ˜μ–΄ 있음

  • ν”„λ‘œμ νŠΈ λ‚΄ νŒŒμΌμ— μ ‘κ·Όν•  일이 μžˆμ„ 경우 ν™œμš© (주둜 classpath ν•˜μœ„ 파일)

  • λŒ€λΆ€λΆ„μ˜ μ‚¬μ „μ •μ˜λœ νŒŒμΌλ“€μ€ μžλ™μœΌλ‘œ λ‘œλ”©λ˜λ„λ‘ λ˜μ–΄ μžˆμœΌλ‚˜, μΆ”κ°€λ‘œ ν•„μš”ν•œ 파일이 μžˆμ„ λ•Œ ν™œμš© κ°€λŠ₯

ResourcePatternResolver

μŠ€ν”„λ§ ApplicationContext μ—μ„œ ResourceLoader λ₯Ό 뢈러올 λ•Œ μ‚¬μš©ν•˜λŠ” Interface μœ„μΉ˜ μ§€μ •μž νŒ¨ν„΄μ— 따라 μžλ™μœΌλ‘œ Resouce λ‘œλ” κ΅¬ν˜„μ²΄λ₯Ό 선택 ("classpath:", "file:", "http:")

Application Contexts & Resource Paths

applicationContext λ₯Ό μ΄λ£¨λŠ” μ„€μ • 값을 κ°€μ Έμ˜€λŠ” 방법듀

Last updated