【问题标题】:404 Not Found after deploy java web application .war file部署 java Web 应用程序 .war 文件后找不到 404
【发布时间】:2017-12-04 11:48:58
【问题描述】:

我使用 Spring 框架在 java 中编写了一个 Web 应用程序。对其进行测试并部署到远程tomcat服务器。部署后我收到消息OK - Started application at context path [/proxynator]。但是,如果我使用像 http://109.206.178.66:8080/proxynator/http://109.206.178.66:8080/proxynator/proxynator/test 这样的链接,我有 404 – Not FoundDescription: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. 在应用程序中,我有入门课程

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

和控制器

@RestController
@RequestMapping("/proxynator")
public class MainController {

    @Autowired
    private ProxyRepo proxyRepo;

    @Autowired
    private CountryRepo countryRepo;

    @RequestMapping("/countries")
    @ResponseBody
    public List<Country> findCountries() {

      return countryRepo.findAll();
    }

    @RequestMapping("/test")
    @ResponseBody
    public String testMethod() {

      return "HELLO";
    }

}

我不知道,为什么我有这个问题,因为我设置了我的 tomcat 服务器正确,我的控制器的路径是正确的并且服务器上的应用程序正在运行。 任何想法如何解决它?

更新

我的控制器被更改为:

@RestController
public class MainController {

  @Autowired
  private CountryRepo countryRepo;

  @RequestMapping("/countries")
  @ResponseBody
  public List<Country> findCountries() {

      return countryRepo.findAll();
  }

  @RequestMapping("/")
  @ResponseBody
  public String testMethod() {

      return "HELLO";
  }

}

现在我的输入点是/,它调用testMethod(),但它也不起作用。

【问题讨论】:

  • 它在 109.206.178.66:8080 上工作吗?
  • 是的,它工作。这是tomcat的起始页。
  • 你能在spring boot日志中看到请求映射吗?
  • 我该怎么做?当我在本地启动应用程序时,我可以看到日志,并且一切运行良好。但是当我在远程服务器上部署应用程序时,这一切都不起作用,我看不到日志。可能我不知道该怎么做。
  • 在我看来 109.206.178.66:8080 不应该工作,因为您的类级别映射是 /proxynator。 109.206.178.66:8080/proxynator 不应该像您在方法级别映射中没有“/”那样工作。 109.206.178.66:8080/proxynator/proxynator/test 我认为应该可以。对于日志,您可以检查运行 java 应用程序的服务器上的控制台输出。 (或者您是否有任何将日志重定向到其他位置的日志记录配置)。您也可以尝试109.206.178.66:8080/mappings 查看所有 url 映射(如果您使用的是 spring-boot-starter-actuator)

标签: java spring tomcat server


【解决方案1】:

为了解决这个问题,我扩展了SpringBootServletInitializer 并覆盖了配置方法`

@Override
override fun configure(application: SpringApplicationBuilder?): 
SpringApplicationBuilder {
    return super.configure(application)
}

我改变了项目结构,就像在官方文档中一样。现在效果很好。

PS

我正在将项目重写为 Kotlin

【讨论】:

    猜你喜欢
    • 2017-11-12
    • 2011-07-17
    • 1970-01-01
    • 2020-01-04
    • 2011-01-14
    • 2015-02-09
    • 2015-07-29
    • 2018-04-16
    • 2012-03-26
    相关资源
    最近更新 更多