Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring Boot Maven webapp文件夹和ResourceHandler_Java_Spring_Maven_Spring Boot - Fatal编程技术网

Java Spring Boot Maven webapp文件夹和ResourceHandler

Java Spring Boot Maven webapp文件夹和ResourceHandler,java,spring,maven,spring-boot,Java,Spring,Maven,Spring Boot,在使用Spring Boot的Maven项目中,我有一个包含静态内容(Html、CSS、JavaScript文件)的文件夹: 这是我的应用程序属性: server.port: 8080 server.contextPath: /admin-api 当用户访问以下url时:http://localhost:8080/admin-api/docs我想向他展示/src/main/webapp/docs/文件夹中的静态内容 我正在尝试在我的WebMVCConfigureAdapter中配置Resour

在使用Spring Boot的Maven项目中,我有一个包含静态内容(Html、CSS、JavaScript文件)的文件夹:

这是我的应用程序属性:

server.port: 8080
server.contextPath: /admin-api
当用户访问以下url时:
http://localhost:8080/admin-api/docs
我想向他展示
/src/main/webapp/docs/
文件夹中的静态内容

我正在尝试在我的
WebMVCConfigureAdapter
中配置
ResourceHandler
,但它不起作用:

@EnableWebMvc
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String[] staticResourceMappingPath = { "/docs/", "classpath:/docs/" };
        registry.addResourceHandler("/docs").addResourceLocations(staticResourceMappingPath);
    }

...
}
http://localhost:8080/admin-api/docs
返回404未找到


我做错了什么以及如何正确配置它?

您的
addResourceHandlers
方法应该如下所示

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
     registry.addResourceHandler("/docs/**").addResourceLocations("/docs/");
}

现在,如果在docs文件夹中有一个静态页面,比如
index.html
,那么您可以使用访问它,您的
addResourceHandlers
方法如下所示

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
     registry.addResourceHandler("/docs/**").addResourceLocations("/docs/");
}
现在,如果您在docs文件夹中有一个静态页面,比如
index.html
,那么您可以使用