Restful webservices(Apache wink+Guice+openjpa)

312 Views Asked by At

I would like to use the following technologies to develop restful webservice.

Apache wink+Guice3+openjpa. I dont know how to use guice with wink and openjpa. could you please explain.

1

There are 1 best solutions below

0
On

I can't help you with OpenJPA, but I just now figured out how to use Guice with Wink. First of all, you do not need to use Guice's guice-servlet JAR as you would with a plain webapp. Just set up your webapp to use Wink as you normally would, then follow these steps.

  1. Replace the wink-server JAR with the wink-guice-server JAR (available from the same source).
  2. Change the servlet-class in your web.xml file from

    org.apache.wink.server.internal.servlet.RestServlet

    to

    org.apache.wink.guice.server.internal.servlet.GuiceRestServlet

  3. Also in web.xml, add this snippet to Wink's <servlet-class> element:

    <init-param>
        <param-name>deploymentConfiguration</param-name>
        <param-value>com.yourco.yourproj.DeploymentConfiguration</param-value>
    </init-param>
    
  4. Finally, create a new Wink DeploymentConfiguration class, which I call here com.yourco.yourproj.DeploymentConfiguration.

    package com.yourco.yourproj;
    
    import com.google.inject.Module;
    import org.apache.wink.guice.server.internal.GuiceDeploymentConfiguration;
    import org.apache.wink.guice.server.internal.lifecycle.WinkGuiceModule;
    
    public class DeploymentConfiguration extends GuiceDeploymentConfiguration {
        @Override
        public Module[] createModules() {
            return new Module[] { new WinkGuiceModule(), new YourModule() };
        }
    }
    

    YourModule is just a normal Guice module.