我正在尝试在 Wildfly 服务器中编写 REST API。而且,什么是默认的休息上下文?我的项目名为 eventapp,请求映射为 /user。因此,我尝试了 localhost:8080/eventapp/user 但响应为 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。而且,我正在部署的战争模块名为 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;
}