[英]Unable to display index.html in jax rs with spring boot
I am trying to create a simple app with jax rs, springboot, angular.我正在尝试使用 jax rs、springboot、angular 创建一个简单的应用程序。
I have placed the index.html in static folder, but while hitting the url localhost:8080/index.html or localhost:8080 it's throwing 404 not found error through the custom exception handler.我已将 index.html 放在静态文件夹中,但是在访问 url localhost:8080/index.html 或 localhost:8080 时,它通过自定义异常处理程序抛出 404 not found 错误。 I have added index.html as welcome-file-list.我已将 index.html 添加为欢迎文件列表。
I have a controller class but i have not written any specific method to handle it.我有一个控制器类,但我没有编写任何特定的方法来处理它。
Also i want to display error specific page with message details.我还想显示带有消息详细信息的错误特定页面。
Definitely i am missing something but not getting any pointer to find it out.肯定我错过了一些东西,但没有得到任何指针来找到它。 Please help.请帮忙。
Do i need to configure web.xml explicitly for this?我需要为此明确配置 web.xml 吗?
Add添加
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
To your pom.xml file, spring boot auto configure all the rest.到你的 pom.xml 文件,spring boot 自动配置所有其余的。
I know this is older, but to expand on Itsik's answer I found this answer via this other answer to be very helpful in explaining this.我知道这是旧的,但为了扩展Itsik的答案,我发现这个答案通过this other answer非常有助于解释这一点。
Summed up, if you want to be able to serve up resources/static/index.html
AND use JAX-RS/jersey
for api endpoints, include both spring-boot-start-web
and spring-boot-starter-jersey
.总而言之,如果您希望能够提供resources/static/index.html
并使用JAX-RS/jersey
作为 api 端点,请同时包含spring-boot-start-web
和spring-boot-starter-jersey
。 In your JerseyConfig add @ApplicationPath("/api")
or whatever subpath you want all your jax-rs rest endpoints to live under.在您的 JerseyConfig 添加@ApplicationPath("/api")
或您希望所有 jax-rs rest 端点都存在的任何子路径。 Then you will be able to have the best of both worlds.然后,您将能够两全其美。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.