猿问

Springboot:无法点击网址

运行 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


慕勒3428872
浏览 193回答 1
1回答

跃然一笑

看起来您的 servlet 容器没有启动。请尝试添加此 maven 依赖项&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-web</artifactId>&nbsp; &nbsp; </dependency>您可以删除这些依赖项:&nbsp;<dependency>&nbsp; &nbsp; <groupId>org.springframework</groupId>&nbsp; &nbsp; <artifactId>spring-web</artifactId>&nbsp;</dependency>&nbsp;<dependency>&nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; <artifactId>spring-boot-starter</artifactId>&nbsp;</dependency>它们由建议的启动器提供。
随时随地看视频慕课网APP

相关分类

Java
我要回答