运行 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
提交
取消