[英]apache cxf simple REST api returns always 404
I have a test task - small REST api in apache CXF, which should take stock exchange rates from remote resources.我有一个测试任务 - apache CXF 中的小型 REST api,它应该从远程资源获取股票汇率。 I run this as a maven project (.war) and deploy through TomEE.
我将它作为 Maven 项目 (.war) 运行并通过 TomEE 进行部署。 I'm a newbie in this theme, that's why I can't figure out, why am I always receiving a 404 error.
我是这个主题的新手,这就是为什么我无法弄清楚,为什么我总是收到 404 错误。
that's my service:那是我的服务:
@Path("stock")
public class StockService {
private Stock stock = new Stock();
@GET
@Path("currencies")
@Produces("text/json")
public String getAllCurrencies() {
return stock.getAllCurrenciesJson();
}
@GET
@Path("{currency}/{date}")
@Produces("text/plain")
public String getRateByDate(@PathParam("currency") String currency,
@PathParam("date") String date) {
return stock.findRateByDate(Currency.findByShortcut(currency), date);
}
@GET
@Path("{date}")
@Produces("text/json")
public String getAllRates(@PathParam("date") String date) {
return stock.findAllRatesByDate(date);
}
@GET
@Path("convert/{currency}/{date}")
@Produces("text/plain")
public String getConversionByDate(@PathParam("currency") String currency,
@PathParam("date") String date, Double amount) {
return stock.convert(Currency.findByShortcut(currency), amount, date);
}
}
I hide the model, because the problem is surely with the deployment.我隐藏了模型,因为问题肯定出在部署上。 Then I have several pre-created classes, like:
然后我有几个预先创建的类,例如:
@ApplicationPath("service")
public class MyApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
final Set<Class<?>> classes = new HashSet<>();
//I add this line
classes.add(StockService.class);
return classes;
}
}
@Singleton
@Startup
public class MyStartupBean {
private static final Logger logger = LoggerFactory.getLogger(MyStartupBean.class);
private final ServiceRegistryService serviceRegistryService;
protected MyStartupBean() {
this.serviceRegistryService = null;
}
@Inject
public MyStartupBean(ServiceRegistryService serviceRegistryService) {
this.serviceRegistryService = serviceRegistryService;
}
@PostConstruct
public void init() {
logger.info("Starting service");
serviceRegistryService.registerService();
logger.info("Started service");
}
}
@ApplicationScoped
public class ServiceRegistryService {
private static final Logger logger = LoggerFactory.getLogger(ServiceRegistryService.class);
public void registerService() {
serviceRegistration = ServiceRegistry
.createRegistration("this.service.id:v1", "/service/")
.build();
ServiceRegistry.submitRegistration(serviceRegistration);
logger.info("Service registered as {}", serviceRegistration);
}
}
My web.xml
is empty (means no servlet
or so tags are specified) as well as beans.xml
.我的
web.xml
是空的(意味着没有指定servlet
或 so 标签)以及beans.xml
。 What should I do with those classes or change or add, in order to run my service on the server (.war web-apps on TomEE deploy automatically)?我应该如何处理这些类或更改或添加,以便在服务器上运行我的服务(TomEE 上的 .war web-apps 自动部署)?
PS and I'm not allowed to use Spring PS,我不允许使用 Spring
回答我的问题:问题是 TomEE 不支持 Java 11 的某些功能。我不得不将我的代码降级到 Java 8,然后它就可以工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.