yuehoiwai 2019-07-05 05:31 采纳率: 16.7%
浏览 373
已采纳

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条)

报告相同问题?

悬赏问题

  • ¥15 求高通平台Softsim调试经验
  • ¥15 canal如何实现将mysql多张表(月表)采集入库到目标表中(一张表)?
  • ¥15 wpf ScrollViewer实现冻结左侧宽度w范围内的视图
  • ¥15 栅极驱动低侧烧毁MOSFET
  • ¥30 写segy数据时出错3
  • ¥100 linux下qt运行QCefView demo报错
  • ¥50 F1C100S下的红外解码IR_RX驱动问题
  • ¥20 基于matlab的航迹融合 航迹关联 航迹插补
  • ¥15 用Matlab实现图中的光线追迹
  • ¥15 联想笔记本开机出现系统更新界面