I\'m getting started with Spring DI, but I\'m struggling with dependency injection and the worse part is that I\'m not even sure why as it seems ok to me. Hopefully you guys
Integration Spring with Jersey 2 (org.glassfish.*
):
Some dependencies may be unnecessary, please check & clear it after things got working.
2.5
org.glassfish.jersey.core
jersey-server
${jersey.version}
org.glassfish.jersey.containers
jersey-container-servlet
${jersey.version}
org.glassfish.jersey.core
jersey-client
${jersey.version}
org.glassfish.jersey.test-framework.providers
jersey-test-framework-provider-inmemory
${jersey.version}
org.glassfish.jersey.ext
jersey-spring3
${jersey.version}
org.springframework
spring
org.springframework
spring-core
org.springframework
spring-web
org.springframework
spring-beans
org.springframework
spring-context
my-rest-service
org.glassfish.jersey.servlet.ServletContainer
jersey.config.server.provider.packages
my.package.with.rest.services
1
my-rest-service
/api/*
During the Spring upgrading I had to move it from /main/webapp/WEB-INF/
to /main/resources/
(details).
public interface MyService
{
String work(String s);
}
...
@Service
public class MyServiceImpl implements MyService
{
@Override
public String work(String s)
{
return "Hello, " + s;
}
}
...
@Path("demo/")
@Component
public class DemoRestService
{
@Autowired
private MyService service;
@GET
@Path("test")
public Response test(@FormParam("param") String par)
{
try
{
String entity = service.work(par);
return Response.ok(entity).build();
}
catch (Exception e)
{
e.printStackTrace();
return Response.status(Status.INTERNAL_SERVER_ERROR).entity("Epic REST Failure").build();
}
}
}