SpringBoot:如何为两个不同的映射提供两个不同的HTML文件?

SpringBoot:如何为两个不同的映射提供两个不同的HTML文件?,spring,spring-mvc,spring-boot,Spring,Spring Mvc,Spring Boot,我对Spring Boot非常陌生,我看到如果我启动一个Spring Boot项目并将index.html文件放在src/main/resources/static文件夹中,那么当我打开浏览器并转到地址“localhost:8080”时,我会看到这个文件显示在浏览器中 现在,我有了另一个html文件(我们称之为‘hello.html’),我还将它放在src/main/resources/static中。我编写了以下代码: @Configuration @Controller @EnableAut

我对Spring Boot非常陌生,我看到如果我启动一个Spring Boot项目并将index.html文件放在src/main/resources/static文件夹中,那么当我打开浏览器并转到地址“localhost:8080”时,我会看到这个文件显示在浏览器中

现在,我有了另一个html文件(我们称之为‘hello.html’),我还将它放在src/main/resources/static中。我编写了以下代码:

@Configuration
@Controller
@EnableAutoConfiguration
@ComponentScan
public class TopicController {

@RequestMapping("/hello")
    public String hello() {
        return "hello.html";
    }
}
您可以理解,当我转到localhost:8000/hello时,我希望看到“hello.html”文件的显示

但是,我在控制台中遇到以下错误:

javax.servlet.ServletException:循环视图路径[hello.html]:将 再次发送回当前处理程序URL[/hello.html]。检查你的 ViewResolver设置!(提示:这可能是由于未指定 视图,由于默认视图名称生成。)


您知道我可以做什么吗?这样我就可以在浏览器中获取hello.html文件,以便访问“localhost:8080/hello”

检查您的ViewResolver设置能否添加dispatcher servlet配置?除此之外,请回顾SpringMVC是如何工作的!您不能将
@配置
+
@Controller'+
@组件扫描'混合在一起。花点时间研究Spring您需要配置
InternalResourceViewResolver
。有关详细信息,请参阅。@akuma8,谢谢您的回答。至于研究Spring,我认为Sprint Boot是Spring的轻量级版本。为了了解Sprint引导,我必须学习完整的Spring框架吗?Spring引导是启动Spring项目、简化配置和依赖处理的快速方法。我真的建议您在使用SpringBoot之前了解更多关于Spring的知识,它可以帮助您理解SpringBoot到底有多神奇。我将推荐Graig Walls的《Spring In Action》一书,它对初学者非常有用。我还在读它。