yuehoiwai 2019-07-05 05:31 采纳率: 0%
浏览 372
已采纳

spring boot “hello world”未能成功運行是何原因?

初學spring boot,按照網上教程,用eclipse +maven+spring boot 創建了一個項目,controller非常簡單,代碼如下:

package com.example.demo.Controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class demoController
{
@ResponseBody
@RequestMapping("demo")
public String demo()
{
return "hello world;hello spring boot";
}
}

運行後,console出現以下訊息

2019-07-05 05:08:58.880 INFO 10420 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on LAPTOP-FAS0SHLM with PID 10420 (C:\Users\yueho\eclipse-workspace\demo\target\classes started by yueho in C:\Users\yueho\eclipse-workspace\demo)
2019-07-05 05:08:58.886 INFO 10420 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2019-07-05 05:09:00.430 INFO 10420 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-07-05 05:09:00.470 INFO 10420 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-07-05 05:09:00.470 INFO 10420 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/9.0.13
2019-07-05 05:09:00.480 INFO 10420 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_92\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre1.8.0_92/bin/server;C:/Program Files/Java/jre1.8.0_92/bin;C:/Program Files/Java/jre1.8.0_92/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Java\jdk1.8.0_92\bin;C:\Program Files\Java\jdk1.8.0_92\jre\bin;C:\Users\yueho\AppData\Local\Microsoft\WindowsApps;;C:\Users\yueho\OneDrive\Desktop;;.]
2019-07-05 05:09:00.690 INFO 10420 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-07-05 05:09:00.690 INFO 10420 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1732 ms
2019-07-05 05:09:01.029 INFO 10420 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-07-05 05:09:01.288 INFO 10420 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-07-05 05:09:01.294 INFO 10420 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 2.946 seconds (JVM running for 4.484)

但我在eclipse自帶瀏覽器輸入:http://localhost:8080/,卻出現以下訊息:


The webpage cannot be found

請問問題出在哪裏?

我用的tomcat是maven內崁的,請問如何配置?

  • 写回答

7条回答 默认 最新

  • Burcy Wen 2019-07-05 09:40
    关注

    @RequestMapping("demo")
    你写了接口请求路径,那你应该在http://localhost:8080/demo去访问这个接口得到hello world
    ,如果你的项目还设置有applicationcontext,那你应该再加一层应用名称,如http://localhost:8080/baidu/demo

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥20 firefly-rk3399上启动卡住了
  • ¥15 如何删除这个虚拟音频
  • ¥50 hyper默认的default switch
  • ¥15 网站打不开,提示502 Bad Gateway
  • ¥20 基于MATLAB的绝热压缩空气储能系统代码咨询
  • ¥15 R语言建立随机森林模型出现的问题
  • ¥15 中级微观经济学,生产可能性边界问题
  • ¥15 TCP传输时不同网卡传输用时差异过大
  • ¥15 请各位看看我写的属于什么算法,或者有更正确的写法?
  • ¥15 html5 qrcode 扫描器