这些是我的课:
应用配置
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "jp.co.sample.ai")
public class AppConfig {
}
应用初始化器
public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class[] getRootConfigClasses() {
return new Class[] { AppConfig.class };
}
@Override
protected Class[] getServletConfigClasses() {
return null;
}
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
}
用户控制器
@RestController
public class UserController {
@Autowired
private UserRepository userRepo;
@GetMapping("/users")
public List getUserList(){
return userRepo.findAll();
}
}
用户存储库
@Component
public class UserRepository {
private static List<User> userList;
{
userList = new ArrayList<User>();
userList.add(new User("tk001", "ten", "kin"));
userList.add(new User("tk002", "ten2", "kin2"));
userList.add(new User("tk003", "ten3", "kin3"));
}
public List findAll(){ return userList; }
我的项目结构是这样的
我通过 Tomcat 运行这个项目,但出现错误 404
http://localhost:8080 << 给了我默认的 index.jsp
请帮忙!谢谢。