为了账号安全,请及时绑定邮箱和手机立即绑定

使用Spring Boot App无法达到RESTful服务

使用Spring Boot App无法达到RESTful服务

斯蒂芬大帝 2021-04-26 21:09:46
我正在尝试在Wildfly 13.0.0上运行一个简单的Spring Boot应用程序,但是在尝试访问任何REST URL时总是出现404错误。这是我的应用程序类:package com.application.example;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.builder.SpringApplicationBuilder;import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@SpringBootApplicationpublic class ExampleApp extends SpringBootServletInitializer{    public static void main(String[] args) throws Exception{        SpringApplication.run(ExampleApp.class, args);    }    @Override    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {        return application.sources(applicationClass);    }    private static Class<ExampleApp> applicationClass = ExampleApp.class;}@RestControllerclass HelloController {    @RequestMapping("/hello/{name}")    String hello(@PathVariable String name) {        return "Hi " + name + " !";    }}.war已正确部署,如果我转到localhost:8080 / application-example / index.html,但如果尝试localhost:8080 / application-example / hello或localhost:8080 / application,则可以访问创建的html索引页-example / hello / myName甚至是结尾为0.0.1 Snapshot的原始名称,我总是得到404。当然,内部包中的RestController类也会发生这种情况,但是在上面的示例中,我们位于同一包中,因此我认为这不是可见性/扫描问题。这是我要求的application.properties:我想念什么吗?如果您需要更多详细信息,请询问。
查看完整描述

1 回答

?
繁花不似锦

TA贡献1851条经验 获得超4个赞

Spring Docs中所述,以下内容缺失:

一个流行的话题是,许多人仍然希望生成要在容器内部署的WAR文件。这两个插件也都支持。本质上,您必须重新配置项目以生成WAR文件,并将嵌入式容器依赖项声明为“已提供”。这样可以确保相关的嵌入式容器依赖项不包含在WAR文件中。

要构建一个既可执行又可部署到外部容器的war文件,您需要将嵌入式容器的依赖关系标记为“已提供”,如以下示例所示:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

注意:您不需要排除。

更新 按照此工作项目进行操作githubspring-boot with wildfly以比较缺少的配置。


查看完整回答
反对 回复 2021-05-12
  • 1 回答
  • 0 关注
  • 186 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信