Nikita Kalugin
Nikita Kalugin

Reputation: 742

How can I configure JAX-RS endpoints programmaticaly?

I'm trying to get rid of XML in my project. I already tried to add this:

JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(CustomerService.class);
sf.setAddress("http://localhost:9000/");
sf.create();

to my Activator class, but my bundle wont start with this.

So, how usually people configuring endpoints?

Upvotes: 2

Views: 70

Answers (1)

erdal.karaca
erdal.karaca

Reputation: 713

(Sorry, no code, just some high level insights from my experience/projects)

I use jersey and its integration into the OSGi environment. I.e. org.glassfish.jersey.servlet.ServletContainer to which I register all jax-rs resources. This way, I can use whatever HTTP server implementation is available (for example, jetty) and configure it via the OSGi system environment properties.

For simplicity, I re-register annotated OSGi (declarative) services as singleton resources/endpoints into that ServletContainer.

Maybe, CXF has also a similar approach.

Upvotes: 1

Related Questions