【发布时间】:2018-08-12 23:28:59
【问题描述】:
我正在尝试通过 OSGi(使用 Apache Felix)公开 REST 服务。我正在使用osgi-jax-rs-connector 发布资源。这里是资源接口:
@Path("/bingo")
public interface BingoService {
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/lottery")
List<Integer> getLottery();
}
该实现使用 DS 注释来获取对容器中提供的服务的引用:
@Component(
immediate = true,
service = BingoService.class,
properties = "jersey.properties")
public class Bingo implements BingoService {
@Reference
private RandomNumberGenerator rng;
@Activate
public void activateBingo() {
System.out.println("Bingo Service activated using " +
rng.getClass().getSimpleName());
}
@Override
public List<Integer> getLottery() {
List<Integer> result = new ArrayList<>();
for (int i = 5; i > 0; i--) {
result.add(rng.nextInt());
}
return result;
}
}
jersey.properties 只包含这一行
service.exported.interfaces=*
当我部署捆绑包时,它会启动并正确注册服务。但是如果我去 http://localhost:8181/services/bingo/lottery 我会得到 404。 有人可以指出我的问题或给我一些关于在哪里寻找的建议吗?
【问题讨论】:
标签: rest jax-rs osgi apache-felix declarative-services