我正在尝试在Wildfly服务器中编写REST API。而且,什么是默认休息上下文?我的项目名为eventapp,请求映射为/ user。所以,我尝试了localhost:8080 / eventapp / user但resposne是404.这两个的任何组合也是如此。我的休息控制器类:
@RestController
@RequestMapping(value = "/user")
public class UserRest {
@Autowired
private UserService userService;
@RequestMapping(value = "/", method = RequestMethod.GET)
public List<JsonUser> getAllUsers() {
return userService.getAllUsers();
}
}
我正在和Spring一起使用maven。而且,我正在部署的war模块名为rest_services_war。也许配置类错了?我在conf类中使用的注释: @Configuration 和 @EnableTransactionManagement 。本课程中的方法:
@Bean
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(dataSource());
sessionFactory.setPackagesToScan(new String[] { "com.eventapp.rest.dao_impl" });
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;
}
@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("org.postgresql.Driver");
dataSource.setUrl("jdbc:postgresql://localhost:5432/eventapp");
dataSource.setUsername("username");
dataSource.setPassword("password");
return dataSource;
}