Guice

GWT, Guice and GIN compilation

霸气de小男生 提交于 2019-12-11 04:35:29
问题 I'm trying to build and GWT MVP application using Guice and Gin. I added Guice and GIN jars to my Eclipse project but i'm stuck with this error: java.lang.NoClassDefFoundError: com/google/inject/internal/util/$Preconditions I've done a quick Google search and here says the we need to recompile GIN against GWT SDK. Also, the Gin Tutorial mention something about a compilation step. Isn't enough to add GIN jars to the GWT project, or is mandatory to generate gin.jar from sources? How do i

Creating a custom @TestScoped Guice scope for the duration of a unit test

a 夏天 提交于 2019-12-11 03:55:42
问题 I would like to scope objects so that they exist as singletons for the duration of a unit test. The pattern would follow the @RequestScoped and @SessionScoped already implemented in Google Guice, by would scope around the @Before and the @After of a junit test: public class MyUnitTest { @TestScoped static class MyTestScopedClass { } @Before public void enterTestScope() { // something here creates the TestScope } @After public void exitTestScope() { // destroy the TestScope } @Test public void

When to provide explicit binding and when to leverage the automatic binding on Guice

家住魔仙堡 提交于 2019-12-11 03:15:13
问题 I was wonder, why do we need to provide bindings explicitly sometimes and not other times in the module? How does Guice decide when we need the binding and when not? Is it because if a dependency has no multiple implementations and it is injected elsewhere as a dependencies it will be automatically bound as part of a dependency graph? Thanks 回答1: You need a binding (either through a bind , an @Provides method or an @ImplementedBy annotation) for anything you want injected that is not a

Got UnsupportedActionException with GWT and Maven

笑着哭i 提交于 2019-12-11 02:46:50
问题 I still trying to make my project with GWT and Maven works. Now, i got errors in ActionHandlers. I configured Guice like tutorials in examples and in other project (that isnt working with maven) it works as expected, but, in this project, seems like the guice servlet doesnt bind the Action to ActionHandler in ServerModule: public class ServerModule extends HandlerModule { @Override protected void configureHandlers() { System.out.println("ServerModule.configureHandlers()"); install(new

Proper structure for dependency injection (using Guice)

安稳与你 提交于 2019-12-11 02:38:48
问题 I would like some suggestions and feedback on the best way to structure dependency injection for a system with the structure described below. I'm using Guice and thus would prefer solutions centered around it's annotation-based declarations, not XML-heavy Spring-style configuration. Consider a set of similar objects, Ball, Box, and Tube , each dependent on a Logger , supplied via the constructor. (This might not be important, but all four classes happen to be singletons --- of the application

Handling un-mapped Rest path

大城市里の小女人 提交于 2019-12-11 02:37:45
问题 This is my current Guice configuration: public class MyServletModule extends ServletModule { @Override protected void configureServlets() { bind(MyRest.class); serveRegex(".+(?<!\\.(html|css|png|jpg))") .with(HttpServletDispatcher.class); } } However I want that my Rest resource is only access in form of http://127.0.0.1:8888/{hashcode_or_filename} and the only form accepted and processed (well, plus the /create method below). Right now, I can deal with hashcode and filename properly in this

How to bind a class that extends a Trait with a monadic type parameter using Scala Guice?

那年仲夏 提交于 2019-12-11 02:32:40
问题 I need to bind the implementation of this trait: trait ClientRepository[F[_]] { def list(): F[Iterable[ClientDTO]] } to this implementation: import cats.effect.IO @Singleton class ClientRepositoryImpl @Inject()(db: OldDataBase, c: IOContextShift) extends ClientRepository[IO] { override def list(): IO[Iterable[ClientDTO]] = ??? } I'm using Scala Play! v2.7.2 and Scala v2.12.8, with scala-guice v4.2.1. In order to bind the trait to its implementation I would like to do something like that in my

Can Guice's @Singleton annotation be inherited?

自作多情 提交于 2019-12-11 02:32:17
问题 Let's say that I have this class: @Singleton public class Parent { ... } and this class: public class Child extends Parent { ... } in my Java app, and my app relies on Guice injection to create objects. If I create an instance of Child through Injector.createInstance(Child.class) , wiill that instance be a Singleton automatically (because the parent was annotated as a Singleton), or do I need to explicitly add the @Singleton annotation to Child ? 回答1: Nope - you'd need to annotate Child as

Read Aspectj Pointcut definition from property file for LTW

淺唱寂寞╮ 提交于 2019-12-11 02:09:50
问题 I using aspectj LTW in my guice application and I m trying to make the pointcut definition for the aspects controlled from a configuration file. for example: pointcut publicOperation() : execution(*** READ THIS FROM CONFIG/PROPERTY FILE ****); Object around() : publicOperation() { ..... } what all possible options that I have ? Thanks 回答1: Put your pointcut definitions into aop.xml as suggested by the The AspectJ Development Environment Guide. 来源: https://stackoverflow.com/questions/18130336

Inject all implementations of a certain trait/class in play using guice

泄露秘密 提交于 2019-12-11 01:46:05
问题 I have trait Builder[T, K] { def build(brick: T) : K For that trait, i have multiple implementations... class StringBuilder extends Builder[Foo, String] { ... } class HouseBuilder extends Builder[Baa, House] { ... } class BaaBuilder extends Builder[Baz, Int] { ... } Depending on a given Type, i would like to choose from one implementation. Something like this (Pseudo-code): class BuildingComponent @Inject()(builder: Set[Builder]){ def doIt(item: Any) = { item match { case _: Foo => builder