Jersey,Tomcat:IntelliJ 中请求的资源不可用错误
Jersey, Tomcat: The requested resource is not available error in InjelliJ
我是 Jersey 的新手,正在尝试将项目从 Spring MVC 转换为 Jersey。但是,对于我当前的构建,所有请求 return 都是 resource not available
错误。任何帮助将不胜感激。
我的依赖项:
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')
}
我的球衣配置
@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();
}
}
使用 JerseryConfig() 构造函数中的 packages() 方法注册包含球衣资源的包 -
public JersyConfig() {
packages("PACKAGE_CONTAINING_JERSEY_RESOURCES");
registerEndpoints();
configureSwagger();
}
我是 Jersey 的新手,正在尝试将项目从 Spring MVC 转换为 Jersey。但是,对于我当前的构建,所有请求 return 都是 resource not available
错误。任何帮助将不胜感激。
我的依赖项:
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')
}
我的球衣配置
@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();
}
}
使用 JerseryConfig() 构造函数中的 packages() 方法注册包含球衣资源的包 -
public JersyConfig() {
packages("PACKAGE_CONTAINING_JERSEY_RESOURCES");
registerEndpoints();
configureSwagger();
}