Greyshack
Greyshack

Reputation: 1971

Spring Boot custom static resource location outside of project

How can I add a custom resource location that is on for example my D drive in folder called Resources.

@Configuration
public class StaticResourceConfiguration extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        super.addResourceHandlers(registry);
        registry.addResourceHandler("/**").addResourceLocations("D:/Resources/");
    }
}

This doesn't work.

This is my application class and the only other configuration file.

@SpringBootApplication public class Application {

public static void main(String args[]){
    SpringApplication.run(Application.class, args);
}

@Bean // for websocket endpoints
public ServerEndpointExporter serverEndpointExporter() {
    return new ServerEndpointExporter();
}

@Bean
public PasswordEncoder bcryptPasswordEncoder(){
    return new BCryptPasswordEncoder();
}

}

Upvotes: 1

Views: 2843

Answers (2)

Master Slave
Master Slave

Reputation: 28519

You should state your location using the file prefix, check more here . So it should be

registry.addResourceHandler("/**").addResourceLocations("file:///D:/Resources/");

Upvotes: 5

luboskrnac
luboskrnac

Reputation: 24561

Try /D:/Resources/. Absolute path must start with /

Upvotes: 0

Related Questions