Search in sources :

Example 86 with ResourceLoader

use of org.springframework.core.io.ResourceLoader in project spring-boot by spring-projects.

the class ClassLoaderFilesResourcePatternResolverTests method customResourceLoaderIsUsedInWebApplication.

@Test
void customResourceLoaderIsUsedInWebApplication() {
    GenericWebApplicationContext context = new GenericWebApplicationContext(new MockServletContext());
    ResourceLoader resourceLoader = mock(ResourceLoader.class);
    context.setResourceLoader(resourceLoader);
    this.resolver = new ClassLoaderFilesResourcePatternResolver(context, this.files);
    this.resolver.getResource("foo.txt");
    then(resourceLoader).should().getResource("foo.txt");
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 87 with ResourceLoader

use of org.springframework.core.io.ResourceLoader in project spring-boot by spring-projects.

the class ClassLoaderFilesResourcePatternResolverTests method customResourceLoaderIsUsedInNonWebApplication.

@Test
void customResourceLoaderIsUsedInNonWebApplication() {
    GenericApplicationContext context = new GenericApplicationContext();
    ResourceLoader resourceLoader = mock(ResourceLoader.class);
    context.setResourceLoader(resourceLoader);
    this.resolver = new ClassLoaderFilesResourcePatternResolver(context, this.files);
    this.resolver.getResource("foo.txt");
    then(resourceLoader).should().getResource("foo.txt");
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) Test(org.junit.jupiter.api.Test)

Example 88 with ResourceLoader

use of org.springframework.core.io.ResourceLoader in project spring-boot by spring-projects.

the class SpringApplicationTests method customResourceLoaderFromConstructor.

@Test
void customResourceLoaderFromConstructor() {
    ResourceLoader resourceLoader = new DefaultResourceLoader();
    TestSpringApplication application = new TestSpringApplication(resourceLoader, ExampleWebConfig.class);
    this.context = application.run();
    then(application.getLoader()).should().setResourceLoader(resourceLoader);
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Test(org.junit.jupiter.api.Test)

Example 89 with ResourceLoader

use of org.springframework.core.io.ResourceLoader in project spring-boot by spring-projects.

the class Restarter method prepare.

private void prepare(GenericApplicationContext applicationContext) {
    ResourceLoader resourceLoader = new ClassLoaderFilesResourcePatternResolver(applicationContext, this.classLoaderFiles);
    applicationContext.setResourceLoader(resourceLoader);
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader)

Example 90 with ResourceLoader

use of org.springframework.core.io.ResourceLoader in project spring-boot by spring-projects.

the class SpringApplication method printBanner.

private Banner printBanner(ConfigurableEnvironment environment) {
    if (this.bannerMode == Banner.Mode.OFF) {
        return null;
    }
    ResourceLoader resourceLoader = (this.resourceLoader != null) ? this.resourceLoader : new DefaultResourceLoader(null);
    SpringApplicationBannerPrinter bannerPrinter = new SpringApplicationBannerPrinter(resourceLoader, this.banner);
    if (this.bannerMode == Mode.LOG) {
        return bannerPrinter.print(environment, this.mainApplicationClass, logger);
    }
    return bannerPrinter.print(environment, this.mainApplicationClass, System.out);
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader)

Aggregations

ResourceLoader (org.springframework.core.io.ResourceLoader)90 Resource (org.springframework.core.io.Resource)51 Test (org.junit.Test)35 ClassRelativeResourceLoader (org.springframework.core.io.ClassRelativeResourceLoader)34 File (java.io.File)33 DefaultResourceLoader (org.springframework.core.io.DefaultResourceLoader)26 Test (org.junit.jupiter.api.Test)15 IOException (java.io.IOException)9 Environment (org.springframework.core.env.Environment)9 ByteArrayResource (org.springframework.core.io.ByteArrayResource)7 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)6 FileSystemResource (org.springframework.core.io.FileSystemResource)6 HashMap (java.util.HashMap)5 Configuration (freemarker.template.Configuration)4 Template (freemarker.template.Template)4 InputStream (java.io.InputStream)4 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)4 InputStreamReader (java.io.InputStreamReader)3 Properties (java.util.Properties)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3