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());
}
}
}
测试结果:
<