GithubHelp home page GithubHelp logo

jersey2-guice's Introduction

Jersey 2.0 w/ Guice

Continuous Integration

Introduction

This library provides support for Jersey 2.0 w/ Guice similar to the way it used to work in Jersey 1.x with the jersey-guice library. It uses Guice's own GuiceFilter (like jersey-guice) and it's somewhat different from the Guice/HK2 Bridge.

Installation

Go to search.maven.org and search for g:"com.squarespace.jersey2-guice" AND a:"jersey2-guice-impl" to find the current release version.

Gradle

compile "com.squarespace.jersey2-guice:jersey2-guice-impl:${current.version}"

Maven

<dependency>
  <groupId>com.squarespace.jersey2-guice</groupId>
  <artifactId>jersey2-guice-impl</artifactId>
  <version>${current.version}</version>
</dependency>

Usage

Getting Started

Jersey/HK2 uses unfortunately SPIs and the Singleton pattern internally. Your code is effectively racing against the Servlet container's code and the first one to initialize HK2's ServiceLocatorGenerator inside its ServiceLocatorFactory wins.

This library uses two approaches to override HK2's own ServiceLocatorGenerator. It first tries to use a SPI and if it can't it'll fall back to reflection to replace a private static field. Regardless of the approach it's still a race against the Servlet container.

public static void main(String[] args) {

  List<Module> modules = new ArrayList<>();
  
  modules.add(new JerseyGuiceModule("__HK2_Generated_0"));
  modules.add(new ServletModule());
  modules.add(new AbstractModule() {
    @Override
    protected void configure() {
      // ...
    }
  });
  
  Injector injector = Guice.createInjector(modules);
  JerseyGuiceUtils.install(injector);
  
  // ... continue ...
}

Documentation

The User's Guide can be found in the Wiki.

Apache 2.0 License

Copyright 2014-2016 Squarespace, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

jersey2-guice's People

Contributors

rkapsi avatar abrandimarti avatar oillio avatar jontejj avatar fkirill avatar squinn avatar twz123 avatar mrserverless avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.