Spring 引导属性以更改前端资源的目录



我有一个 Spring Boot 应用程序,我想更改前端的目录。与其将前端资源放在目录resources/static内,我想将它们移动到resources之外的另一个目录。我需要更改哪些属性,以便我的应用程序考虑用于呈现前端的新目录?

您可以使用WebMvcConfigurerAdapter配置其他资源映射:

@Component
public class ResourcesMvcAdapter extends WebMvcConfigurerAdapter {
private final Path resourcePath = Paths.get( ... );
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**")
.addResourceLocations(resourcePath.toUri().toString()); 
}
}