Simple example showing the problem described in Netflix/governator#89
Versions
- Karyon, 1.0.20
- Governator, 1.2.3
- Jersey, 1.9.1
- Guice, 3.0
Simple example showing the problem described in Netflix/governator#89
Versions
| # Karyon properties | |
| com.netflix.karyon.server.base.packages=foo | |
| com.netflix.karyon.eureka.disable=true | |
| com.netflix.karyon.server.bootstrap.class=foo.MyServerBootstrap |
| package foo; | |
| public interface Feature { | |
| public String getName(); | |
| } |
| package foo; | |
| import com.netflix.governator.annotations.AutoBindSingleton; | |
| @AutoBindSingleton(baseClass = Feature.class, multiple = true) | |
| public class FeatureA implements Feature { | |
| @Override | |
| public String getName() { | |
| return "FeatureA"; | |
| } | |
| } |
| package foo; | |
| import com.netflix.governator.annotations.AutoBindSingleton; | |
| @AutoBindSingleton(baseClass = Feature.class, multiple = true) | |
| public class FeatureB implements Feature { | |
| @Override | |
| public String getName() { | |
| return "FeatureB"; | |
| } | |
| } |
| package foo; | |
| import java.util.Set; | |
| import javax.ws.rs.Path; | |
| import com.google.inject.Inject; | |
| import com.sun.jersey.spi.resource.Singleton; | |
| import foo.Feature; | |
| @Singleton | |
| @Path("/foo") | |
| public class MyResource { | |
| @Inject | |
| public MyResource(Set<Feature> features) { | |
| System.err.println(">>>>>>> " + features + " <<<<<<<"); | |
| } | |
| } |
| package foo; | |
| import java.util.Map; | |
| import com.google.common.collect.Maps; | |
| import com.netflix.governator.guice.BootstrapBinder; | |
| import com.netflix.karyon.server.ServerBootstrap; | |
| import com.sun.jersey.guice.JerseyServletModule; | |
| import com.sun.jersey.guice.spi.container.servlet.GuiceContainer; | |
| public class MyServerBootstrap extends ServerBootstrap { | |
| protected void configureBootstrapBinder(BootstrapBinder bootstrapBinder) { | |
| bootstrapBinder.install(new JerseyServletModule() { | |
| @Override | |
| protected void configureServlets() { | |
| Map<String, String> params = Maps.newHashMap(); | |
| params.put("com.sun.jersey.config.property.packages","foo"); | |
| params.put("com.sun.jersey.api.json.POJOMappingFeature", "true"); | |
| bind(GuiceContainer.class).asEagerSingleton(); | |
| serve("/*").with(GuiceContainer.class, params); | |
| } | |
| }); | |
| } | |
| } | |
| <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" | |
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| xsi:schemaLocation="http://java.sun.com/xml/ns/javaee "> | |
| <filter> | |
| <filter-name>guiceFilter</filter-name> | |
| <filter-class>com.google.inject.servlet.GuiceFilter</filter-class> | |
| </filter> | |
| <filter-mapping> | |
| <filter-name>guiceFilter</filter-name> | |
| <url-pattern>/*</url-pattern> | |
| </filter-mapping> | |
| <listener> | |
| <listener-class>com.netflix.karyon.server.guice.KaryonGuiceContextListener</listener-class> | |
| </listener> | |
| </web-app> |