Tuesday, January 22, 2013

spring mvs vs jax-rs rest

 Q:
Any reason why i should choose jax-rs (jersey ) instead of Spring-mvc for rest implementation.
Spring comes with additional features in addition to rest like aop , security , ioc etc. . You get all you need form spring.
Any performance/features drawbacks choosing spring (i suspect that ).


 A:
JAX-RS pros:
  1. JSR standard
  2. Can be run without servlet container (grizzly, simple, ...)
  3. Production-ready implementations (jersey, cxf, resteasy, restlet, ...)
  4. designed for REST applications only
Spring MVC pros:
  1. Provide "full" stack, not just REST facilities
  2. Dependency injection / AOP / Transactions
  3. Pluggable view templates (JSP, freemarker, velocity, ...)
I've never noticed performances bottlenecks with one or other, except spring application take a longer time to deploy and warm-up.

How to load resource from classpath in java

How to load resource from anywhere in classpath in java.

ClassLoader cl = ClassLoader.getSystemClassLoader();
    if (cl != null) {
        URL url = cl.getResource(CONF_PROPERTIES);
        if (null == url) {
            url = cl.getResource("/" + CONF_PROPERTIES);
        }
        if (null != url) {
            try {
                InputStream in = url.openStream();
                props = new Properties();
                props.load(in);
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }