簡體   English   中英

Spring Boot應用程序無法在Tomcat中配置的端口號上啟動

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

我在spring工具套件工具中運行示例spring boot應用程序。 配置端口后,我無法從瀏覽器啟動應用程序。 我收到404找不到錯誤。 Spring Boot在tomcat上正常運行。

application.properties

hello.greeting =很高興見到你

server.port = 9874

有人可以幫我解決問題。

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)

這是春季啟動應用程序,在下面的鏈接http:// localhost:9874 /上找不到404。

您的網址錯誤。 您必須使用RequestParam名稱調用該URL。

使用此網址http:// localhost:9874 / hello?name = test

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM