结合Spring项目和Jersey

结合Spring项目和Jersey

我用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();
    }}


RISEBY
浏览 474回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP