結(jié)合Spring項(xiàng)目和Jersey我用Spring JPA構(gòu)建了一個(gè)項(xiàng)目,現(xiàn)在我想在我的Jersey項(xiàng)目中使用它。我已將我的SJPA項(xiàng)目添加為我的pom.xml中的依賴項(xiàng)當(dāng)我使用GET / POST / PUT / DELETE方法時(shí),我想使用我的SJPA中的服務(wù)類。使用注釋有一種簡(jiǎn)單的方法嗎?或者我必須AnnotationConfigApplicationContext參加每堂課?感覺有點(diǎn)浪費(fèi)。@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();
}}
添加回答
舉報(bào)
0/150
提交
取消