【发布时间】:2021-09-17 11:28:59
【问题描述】:
我正在尝试使用以下控制器为每个请求映射返回“index.html”页面:
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class ReactWebController {
@RequestMapping(value = {"/", "/login/**", "/logout/**", "/forgotpassword/**", "/home/**", "/dashboard/**"
, "/user/**", "/profile/**", "/catalog/**", "/permission/**", "/diconnect/**", "/nsm/**", "/session/**"
, "/settings/**", "/log/**", "/config/**", "/delete/**", "/initialize/**", "/initial/**", "/changepassword/**",
"/portalconnect/**", "/portal/**", "/portal/user/**", "/portal/profile/**", "/portal/permission/**",
"/portal/catalog/**", "/portal/metadata-browse/**","/portal/search/**","/portal-object-overview/**"})
public String react() throws Exception {
return "index.html";
}
}
问题是,当我刷新 URL 时,当路径如下:http://localhost:18170/MartServer/user 时它正在工作,但当它具有多个文件夹类型的路径时则不行,例如http://localhost:18170/MartServer/portal/user。我得到以下异常详细信息。
编辑:但在端口 3000(前端)并非如此,我没有进行任何完整项目的构建,后端和前端是分开的。
ERROR [/MartServer].[dispatcherServlet].log: Servlet.service() for servlet [dispatcherServlet] in context with path [/MartServer] threw exception [Circular view path [index.html]: would dispatch back to the current handler URL [/MartServer/portal/index.html] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)] with root cause
javax.servlet.ServletException: Circular view path [index.html]: would dispatch back to the current handler URL [/MartServer/portal/index.html] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
我也尝试添加addViewControllers() 和addResourceHanlders(),但没有成功。谁能帮我解决这个问题。谢谢!
前端为React JS,index.html在“npm run build”后生成,用于控制器
【问题讨论】:
标签: java spring spring-boot spring-mvc