Java Spring代码配置中添加资源位置到磁盘上。

bluesky1年前 ⋅ 167 阅读

ChatGPT的回答仅作参考:

在Java Spring代码配置中,可以通过以下方式将资源位置添加到磁盘上:

1. 在Spring配置文件中添加以下代码:

```xml
<mvc:resources mapping="/resources/**" location="file:/path/to/resources/" />
```

其中,`/resources/**`是资源的URL路径,`file:/path/to/resources/`是资源在磁盘上的路径。

2. 在Java代码中添加以下代码:

```java
@Configuration
@EnableWebMvc
public class AppConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resources/**")
                .addResourceLocations("file:/path/to/resources/");
    }
}
```

其中,`/resources/**`是资源的URL路径,`file:/path/to/resources/`是资源在磁盘上的路径。

注意:在添加资源位置时,需要确保资源路径的正确性,并且需要保证资源所在的目录具有读取权限。

全部评论: 0

    相关推荐