運行 Main 類后,我無法獲得輸出。Spring Boot 新手控制器@Controller public class WelcomeController { private static final String welcomemsg = "Welcome Mr. %s!"; @GetMapping("/welcome/user") @ResponseBody public Welcome welcomeUser(@RequestParam(name = "name", required = false, defaultValue = "Java Fan") String name) { return new Welcome(String.format(welcomemsg, name)); } }主班package com.beans.mainsrc;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication(scanBasePackages = { "com.beans" })public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); }}有關運行主類的控制臺詳細信息2018-09-28 00:40:01.268 INFO 2304 --- [ main] com.beans.mainsrc.DemoApplication : Starting DemoApplication on DESKTOP-551C51M with PID 2304 (F:\springbootdemo\demo\target\classes started by sparsh in F:\springbootdemo\demo) 2018-09-28 00:40:01.273 INFO 2304 --- [ main] com.beans.mainsrc.DemoApplication : No active profile set, falling back to default profiles: default
1 回答

躍然一笑
TA貢獻1826條經驗 獲得超6個贊
看起來您的 servlet 容器沒有啟動。請嘗試添加此 maven 依賴項
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
您可以刪除這些依賴項:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
它們由建議的啟動器提供。
添加回答
舉報
0/150
提交
取消