搭建SSM无法访问Controller解决方案

本文描述了在搭建SSM项目时遇到无法访问Controller的bug,通过场景还原和逐步排查,发现是未在web.xml中添加DispatcherServlet配置以及在controller配置文件中未开启springmvc模式。解决这两个问题后,成功访问了Controller。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.场景还原

    拳不离手,曲不离口;由于笔者前期项目多用springboot构建,今天兴起构建一个springmvc项目,但是在访问controller的时候遇到了一个bug,The origin server did not find a current representation for the target resource or is not willing to disclose that one exists。笔者自以为万事俱备,只欠东风的时候,却无法访问controller,代码写的一点问题都木有,怎么访问不成功呢?

2.解决方案

①创建测试类,测试是否数据库连接成功

 

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring/spring-*.xml")
public class UserServiceImplTest {
    @Autowired
    UserService userService;

    @Test
    public void test(){
      List<User> userList = userService.getUserInfo();
       for(User l :userList){
           System.out.println(l.getUsername());
       }
    }

}

测试结果:

<
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

老张家的独苗

可以吃鸡腿????么!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值