【发布时间】:2015-09-02 14:25:46
【问题描述】:
我已经使用 Spring JPA 构建了一个项目,现在我想在我的 Jersey 项目中使用它。 我已将我的 SJPA 项目添加为我的 pom.xml 中的依赖项
当我使用 GET/POST/PUT/DELETE 方法时,我想使用我的 SJPA 中的服务类。
有没有一种简单的方法可以通过注释来做到这一点?或者我必须在每个班级获得AnnotationConfigApplicationContext?感觉有点浪费。
@Path("/users")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public final class UserResource
{
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
private PodcastService service;
@GET
public Response getAllPodcasts() {
context.scan("org.villy.spring.service");
context.refresh();
service= context.getBean(PodcastService.class);
return Response.ok(service.findAll()).build();
}
}
【问题讨论】: