gpt4 book ai didi

java - Spring启动示例: Can't access reSTLet from browser

转载 作者:行者123 更新时间:2023-11-30 07:04:23 25 4
gpt4 key购买 nike

我尝试基于此 spring-boot guide 构建一个非常基本的 Spring Boot 示例。测试按预期工作,但我无法通过 http://localhost/ei-bacon/test 访问 ReSTLet因为它会返回 HTTP 404 错误。

HelloController.java:

@RestController
public class HelloController {

@RequestMapping("/")
public String index() {
return "Ei Bacon welcomes you!";
}

@RequestMapping("/test")
public String test() {
return "Ei Bacon welcomes you again!";
}
}

索引文件(/index.html)和第一个请求映射可能存在冲突。但是第二个(/test)应该可以工作,但没有。我是否输入了错误的网址?

上下文.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/ei-bacon"/>

应用程序.java:

package ch.ffhs.innt.eibacon.hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

最佳答案

如果您将应用程序作为独立的 Spring Boot 应用程序运行,并且不将其部署到应用程序服务器中,则正确的 URL 将为 http://localhost:8080/testhttp//localhost:8080/,如指南中所示。

如果您想将其作为 WAR 文件部署在应用程序服务器或独立 Tomcat 中,您的主类必须扩展 SpringBootServletInitializer 并实现方法 configure(SpringApplicationBuilder),如此处的手册所示:http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file

关于java - Spring启动示例: Can't access reSTLet from browser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40391474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com