猿问

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

我正在尝试在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;



@SpringBootApplication

public 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;



}


@RestController

class HelloController {


    @RequestMapping("/hello/{name}")

    String hello(@PathVariable String name) {


        return "Hi " + name + " !";


    }

}

.war已正确部署,如果我转到localhost:8080 / application-example / index.html,但如果尝试localhost:8080 / application-example / hellolocalhost:8080 / application,则可以访问创建的html索引页-example / hello / myName甚至是结尾为0.0.1 Snapshot的原始名称,我总是得到404。

当然,内部包中的RestController类也会发生这种情况,但是在上面的示例中,我们位于同一包中,因此我认为这不是可见性/扫描问题。

这是我要求的application.properties:


我想念什么吗?如果您需要更多详细信息,请询问。


斯蒂芬大帝
浏览 187回答 1
1回答

繁花不似锦

如Spring Docs中所述,以下内容缺失:一个流行的话题是,许多人仍然希望生成要在容器内部署的WAR文件。这两个插件也都支持。本质上,您必须重新配置项目以生成WAR文件,并将嵌入式容器依赖项声明为“已提供”。这样可以确保相关的嵌入式容器依赖项不包含在WAR文件中。要构建一个既可执行又可部署到外部容器的war文件,您需要将嵌入式容器的依赖关系标记为“已提供”,如以下示例所示:&nbsp;&nbsp;&nbsp;&nbsp;<dependency> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<groupId>org.springframework.boot</groupId> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<artifactId>spring-boot-starter-tomcat</artifactId> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<scope>provided</scope> &nbsp;&nbsp;&nbsp;&nbsp;</dependency>注意:您不需要排除。更新&nbsp;按照此工作项目进行操作github,spring-boot with wildfly以比较缺少的配置。
随时随地看视频慕课网APP

相关分类

Java
我要回答