springboot启动正常,访问时报404问题

在创建的SpringBoot项目中,尽管能够正常启动,但尝试访问127.0.0.1:8080/test时出现404错误。问题出在启动类缺少@RestController注解。添加@RestController后,启动类变为@RestController@SpringBootApplication的公共类,解决了404问题。
摘要由CSDN通过智能技术生成

创建新的springboot项目,编写测试test方法,然后启动工程。
此时启动项目正常,访问:127.0.0.1:8080/test
页面出现404
在这里插入图片描述
后台日志报
在这里插入图片描述
此问题是因为在springboot默认创建的启动类中无**@RestController**注解
package com.example.demo;

import java.util.HashMap;
import java.util.Map;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class Demo3Application {

public static
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值