I use java/jetty self-hosted server and jersey-2 for java RESTful api. Application has application.properties file with properties.
ConfigurationProperties
class reads and loads properties file into java.util.Properties
class.
Jetty server instantiation is done in the following way.
// Create and register resources
final ResourceConfig resourceConfig = new ApiServiceConfig()
.register(new DependencyInjectionBinder());
ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
contextHandler.setContextPath("/mydomain/api");
Server jettyServer = new Server(8585);
jettyServer.setHandler(contextHandler);
ServletHolder jerseyServlet = new ServletHolder(new ServletContainer(resourceConfig));
contextHandler.addServlet(jerseyServlet, "/*");
// Create web context. Can't use.
//WebApplicationContext webContext = getWebApplicationContext();
// Add web context to servlet event listener.
//contextHandler.addEventListener(new ContextLoaderListener(webContext));
try {
jettyServer.start();
jettyServer.join();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
jettyServer.destroy();
}
I can't use Spring AnnotationConfigWebApplicationContext
as it requires commons-logging dependency which doesn't work in java-8.
How can I register Properties with jetty/jersey context and how can I retrieve values later(eg.: context.getProperty("prop.name")
)?