Asked by rsand2
at 2024-08-03 21:03:59
Point:500 Replies:2 POST_ID:828693USER_ID:11587
Topic:
Miscellaneous Programming;;Java Programming Language
I am trying to understand how to properly use the ResourceConfig class in Jersey 2.0. What is the proper Jersey2 pattern for configuring a web application with environment-specific parameters (e.g. backend database connection info)? The point is to configure the application when deployed on Jersey Server, and also to configure the application when launched via JerseyTest.
Can I use ResourceConfig for this purpose? If so, can someone point to an example of how to use it to configure an Application in a Jersey Server?
Some more background on my question and what I'm trying to achieve:
Here's a simple example of what I'm doing with my other servlets (e.g. unrelated to Jersey):
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>com.idfconnect.MyServlet</servlet-class>
<init-param>
<param-name>myAppConfigFile</param-name>
<param-value>/etc/idfconnect/myapp.conf</param-value>
</init-param>
</servlet>
You can see, my servlet reads the param, gets the path to the conf file, and loads
the conf file, which has all of its environment-specific configuration properties.
So the reason for this post is that I want to use a similar approach with my Jersey2 application - when deployed on a Jersey server, I have some mechanism to pass in initialization parameters, and when deployed using JerseyTest, I have an alternate mechanism to pass in such parameters. My question is what is the proper technique in Jersey2 to accomplish this?
Thanks for any help!
Can I use ResourceConfig for this purpose? If so, can someone point to an example of how to use it to configure an Application in a Jersey Server?
Some more background on my question and what I'm trying to achieve:
Here's a simple example of what I'm doing with my other servlets (e.g. unrelated to Jersey):
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>com.idfconnect.MyServlet</servlet-class>
<init-param>
<param-name>myAppConfigFile</param-name>
<param-value>/etc/idfconnect/myapp.conf</param-value>
</init-param>
</servlet>
You can see, my servlet reads the param, gets the path to the conf file, and loads
the conf file, which has all of its environment-specific configuration properties.
So the reason for this post is that I want to use a similar approach with my Jersey2 application - when deployed on a Jersey server, I have some mechanism to pass in initialization parameters, and when deployed using JerseyTest, I have an alternate mechanism to pass in such parameters. My question is what is the proper technique in Jersey2 to accomplish this?
Thanks for any help!