简体   繁体   English

Spring Boot应用程序无法在Tomcat中配置的端口号上启动

[英]spring boot application not starting on configured port number in Tomcat

I am running sample spring boot application in spring tool suite tool. 我在spring工具套件工具中运行示例spring boot应用程序。 After configuring the port I am unable to start application from browser. 配置端口后,我无法从浏览器启动应用程序。 I am getting 404 Not found error. 我收到404找不到错误。 Spring boot is running properly on tomcat. Spring Boot在tomcat上正常运行。

application.properties application.properties

hello.greeting= nice to see you hello.greeting =很高兴见到你

server.port=9874 server.port = 9874

Could some one please help me to correct the problem. 有人可以帮我解决问题。

package demo;

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

@SpringBootApplication
public class HelloBootApplication {

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


package demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @Autowired
    HelloProperties props;

    @RequestMapping("/hello")
    public String hello(@RequestParam String name) {
        return props.getGreeting()+name;
    }

}

package demo;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties("hello")
public class HelloProperties {
    private String greeting = "Welcome ";

    public String getGreeting() {
        return greeting;
    }

    public void setGreeting(String greeting) {
        this.greeting = greeting;
    }
}

2018-07-22 17:17:32.798  INFO 11824 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-07-22 17:17:32.952  INFO 11824 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-07-22 17:17:33.000  INFO 11824 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 9874 (http) with context path ''
2018-07-22 17:17:33.006  INFO 11824 --- [           main] demo.HelloBootApplication                : Started HelloBootApplication in 2.083 seconds (JVM running for 2.862)

This is spring boot application, getting 404 Not Found on below link http://localhost:9874/ 这是春季启动应用程序,在下面的链接http:// localhost:9874 /上找不到404。

Your url is wrong . 您的网址错误。 You have to call the url with RequestParam name. 您必须使用RequestParam名称调用该URL。

use this url http://localhost:9874/hello?name=test 使用此网址http:// localhost:9874 / hello?name = test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Boot 应用程序未在 Tomcat 上启动 - Spring boot application not starting on Tomcat Spring Boot application in eclipse,Tomcat connector配置为监听端口XXXX启动失败 - Spring Boot application in eclipse, the Tomcat connector configured to listen on port XXXX failed to start Spring Boot:配置监听8080端口的Tomcat连接器启动失败 - Spring Boot: The Tomcat connector configured to listen on port 8080 failed to start Spring Boot应用程序未启动嵌入式Tomcat - Spring boot application not starting embedded tomcat Spring启动应用程序使用的端口号 - Port number used by spring boot application 错误启动子部署 spring 引导 web 应用程序到 Tomcat 9 - Error starting child deploying spring boot web application to Tomcat 9 Spring 引导应用程序未启动。 错误:停止服务 [Tomcat] - Spring Boot Application not starting. Error: Stopping Service [Tomcat] 在外部TOMCAT中启动后,Spring Boot Application立即关闭 - Spring Boot Application immediately shuts down after starting in external TOMCAT 如何使用Spring Boot应用程序更改嵌入式tomcat连接器端口 - How to change embedded tomcat connector port using spring boot application https 后的 Spring 启动:配置为侦听端口 8444 的 Tomcat 连接器启动失败。 - Spring boot after https: The Tomcat connector configured to listen on port 8444 failed to start.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM