相关疑难解决方法(0)

Java Spring Boot:如何将我的应用程序根目录("/")映射到index.html?

我是Java和Spring的新手.如何将我的应用程序根映射http://localhost:8080/到静态index.html?如果我导航到http://localhost:8080/index.html它的工作正常.

我的app结构是:

迪尔斯

config\WebConfig.java看起来像这样:

@Configuration
@EnableWebMvc
@ComponentScan
public class WebConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("/");
        }
}
Run Code Online (Sandbox Code Playgroud)

我试图添加registry.addResourceHandler("/").addResourceLocations("/index.html");但它失败了.

java spring spring-boot

121
推荐指数
9
解决办法
15万
查看次数

标签 统计

java ×1

spring ×1

spring-boot ×1