4

I am new to Jersey and trying to convert a project from Spring MVC into Jersey. With my current build however, all requests return a resource not available error. Any help would be greatly appreciated.

My Dependencies:

dependencies { compile('org.springframework.boot:spring-boot-starter') compile("org.springframework.boot:spring-boot-starter-data-jpa:1.4.0.RELEASE") compile("org.springframework.boot:spring-boot-starter-jersey") runtime('org.hsqldb:hsqldb') compileOnly("org.springframework.boot:spring-boot-starter-tomcat") testCompile('org.springframework.boot:spring-boot-starter-test') } 

My Jersey Config

 @Configuration public class JersyConfig extends ResourceConfig { public JersyConfig() { registerEndpoints(); configureSwagger(); } private void configureSwagger() { register(ApiListingResource.class); BeanConfig beanConfig = new BeanConfig(); beanConfig.setVersion("1.0.0"); beanConfig.setSchemes(new String[]{"http"}); beanConfig.setHost("localhost:8090"); beanConfig.setBasePath("/"); beanConfig.setResourcePackage(OwnerController.class.getPackage().getName()); beanConfig.setPrettyPrint(true); beanConfig.setScan(true); } private void registerEndpoints() { register(OwnerController.class); } } @Api(value = "Owner controller", tags = {"Owner resource"}) public class OwnerController { private final ClinicService clinicService; @Autowired public OwnerController(ClinicService clinicService) { this.clinicService = clinicService; } @GET @Path("/{ownerId}") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "get owner by id", response = Owner.class) public Response getOwner( @ApiParam(name = "owner id", value = "owner id that must be fetched") @PathParam("ownerId") int id ) { Owner owner = clinicService.findOwnerById(id); return Response.status(200).entity(owner).build(); } @GET @Path("/owners") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "get all owners", response = Owner.class, responseContainer = "List") public Response getOwners() { List<Owner> owner = (List<Owner>) clinicService.findAllOwners(); return Response.status(200).entity(owner).build(); } } 
3
  • 1
    You should register your package which contains jersey resources using packages() method in JerseyConfig() constructor Commented Nov 22, 2016 at 13:29
  • Thanks, it worked. Commented Nov 23, 2016 at 8:15
  • OK, I will write this as answer. Please accept that. Commented Nov 23, 2016 at 11:07

1 Answer 1

1

Register your package which contains jersey resources using packages() method in JerseryConfig() constructor -

public JersyConfig() { packages("PACKAGE_CONTAINING_JERSEY_RESOURCES"); registerEndpoints(); configureSwagger(); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.