carlspring
carlspring

Reputation: 32587

Proper way to initialize settings for a Jersey restlet

I am trying to find out what is the proper way to initialize a static settings object, which should be loaded once and re-used by the restlets? Should I create a servlet which auto-loads, or is there (I am almost sure) a better way to do this?

Let's say I have a configuration.xml and would like to have it loaded so my restlets could start using it's settings. What would be the proper and most efficient way to do this?

Many thanks in advance!

Upvotes: 0

Views: 136

Answers (1)

TheArchitect
TheArchitect

Reputation: 2173

You can create a ServletFilter that you map to your REST URLs in web.xml:

  <filter-mapping>
    <filter-name>MyServletFilter</filter-name>
    <url-pattern>/rest/*</url-pattern>
  </filter-mapping>

Then you override the init method to do your init business:

public class MyServletFilter implements javax.servlet.Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        loadConguration();
    }

Upvotes: 1

Related Questions