Questions tagged [guice]
Guice is a lightweight dependency injection framework for Java.
3,147
questions
0
votes
0
answers
9
views
Guice-persist: inconsistent data from EntityManagers
I have a problem with the persistence in a java web application.
We use Ninjaframework (6.8.1) which uses Guice as dependency injection framework and for persisting objects.
I encountered two problems ...
0
votes
0
answers
25
views
Mapping of JDBC connection string parameters to MyBatis properties
I am using mybatis-guice (MyBatisModule) to connect the Java application with the PostgreSQL database.
The connection parameters are sent to MyBatis as named properties (see an example here: https://...
0
votes
0
answers
10
views
Dependency injection in scala using guice
I have the following class
class MigrateJob @Inject()(
val resultsMetadataRepo: ResultsMetadataRepo,
val resultsMetadataDao: ResultsMetadataDao,
...
0
votes
0
answers
14
views
Using toProvider in Google Guice
In Google Guice, we could do something like:
public class DSM extends AbstractModule {
@Override
protected void configure(){
bind(DSM.class).to(DSMI.class);
}
}
This will simply bind the DSM to a ...
1
vote
0
answers
43
views
How to create a RESTful API with Jersey + Grizzly + Guice + Hibernate
I've spent some time trying to create a RESTful API with Jersey, Grizzly, Guice and Hibernate, and I'm having a very difficult time wrapping my head around how to wire everything together. This is ...
1
vote
1
answer
37
views
If I use field injection with Guice, why can I only use the no arg constructor?
Here is an example:
public class Dog implements Animal{
private String color;
@Inject
private Owner owner;
//This constructor always used to build the Dog object.
public Dog(){}...
0
votes
1
answer
24
views
Given ClassA and SubclassA, if I use Google Guice to bind ClassA to SubclassA then will SubclassA be injected as an instance where ClassA gets called?
Say I am given a scenario like this:
@Data
public class ClassA {
private final String name = "ClassA";
public ClassA(){
//This constructor gets called anyway. Why?
}
}
...
0
votes
1
answer
70
views
java.lang.ClassNotFoundException: com.google.inject.AbstractModule not found by org.mybatis.mybatis-guice
There is a problem that the bundle using mybatis-guice library using the felix framework fails to start.
The running environment is java11 and karaf 4.2.14 versions.
This is the corresponding error ...
0
votes
0
answers
20
views
Guice: Change scope for unit tests?
My code uses Guice to set up its dependency graph; this includes bindings done via @Provides methods on Modules, @Inject annotations on constructors, and programmatic bindings in Module.configure(), ...
0
votes
0
answers
33
views
Distributed tracing using MDC in microservices world of Java with guice injection
I wish to implement the distributed tracing across the microservices by injecting a tracingID (uuid) in the logs and this tracingID should get propagated to all the downstream service calls.
My ...
1
vote
1
answer
28
views
Apache spark, is it possible to have Google guice as dependency injection technique
Is it possible to use Google guice as dependency injection provider for a Apache spark Java application?
I am able to achieve this if the execution is happening at the driver but no control over when ...
1
vote
2
answers
39
views
Create MessageDigest with Guice
I'm trying to find a way to initialize MessageDigest with Guice. Currently I have this:
public class MyClass {
MessageDigest md;
public MyClass() {
try {
md = ...
0
votes
1
answer
19
views
Is there any way to retrieve a object in a test from a Provide in Guice?
I'm trying to get a Object in a JUnit test from a @Provides in a module which isn't @Injected therefore I cannot get it by the injector.
Is there any way that I can call the method without injecting ...
0
votes
1
answer
21
views
NullPointerException in Guice binding. Am I binding HelperFactory incorrectly?
Here is the following code, where I am getting a NullPointerException. HelperFactory is a Client class, which I cannot change. I am new to Guice, and going through the documentation did not help in ...
0
votes
1
answer
28
views
Datasource injection problems in Jetty 10
I'm in the process of migrating a jetty web app from jetty 9 to jetty 10. We are using google guice to do dependency injection. Currently the guice module looks like this:
public abstract class ...
0
votes
1
answer
24
views
Java binding instance using other instance using Guice
there is a configuration file that I want to bind using Guice but the problem is I get that file using my manager class and I don't have an instance of it. To make clear, I explain on code:
public ...
0
votes
1
answer
33
views
Guice: what happens when I have excessive @Inject on a constructor
I have a class SomeClass and a SomeModule to register it with Guice.
I found out that the constructor SomeClass is only called by SomeModule, and that SomeModule is the only place where binding for ...
0
votes
1
answer
21
views
How to use Guice Injector to avoid declaring string as static
I'm actually new to using Guice injector. I have a situation where I have a String variable in one class and I want to use this variable in a different class without declaring it as static . Can I ...
1
vote
1
answer
40
views
How to do dependency injection for objects created with TypeListener in Guice?
Assuming such module configure method:
@Override
protected void configure() {
bindListener(Matchers.any(), new TranslationKeyListener());
}
class TranslationKeyListener ...
0
votes
1
answer
51
views
How to bind various implementations of interface in Guice
I have a list of multiple implementations of an interface.
public class MyInterfaceImplementation1 extends MyInterface {}
public class MyInterfaceImplementation2 extends MyInterface {}
...
List<...
0
votes
1
answer
29
views
Guice binding a parent concrete class separately from child
I'm trying set up a Guice Module that will allow me to inject a parent class if the field has a certain annotation and a child class if the field does not have that annotation. Both the parent and ...
0
votes
0
answers
17
views
How to override binding in subling child submodules in scala play
I have scala play multimodule application with 3 modules: common, moduleA and moduleB where moduleA and moduleB depend on common.
ModuleA and moduleB should bind different implementation for trait ...
0
votes
1
answer
65
views
How does Guice inject classes without an @Inject-annotated constructor?
I'm trying to understand how DI is used in our codebase (Kotlin). We are using google guice for dependency injection.
Here is a sample class:
class ServiceClass @Inject construct(
private val ...
0
votes
0
answers
29
views
Jersey exception mapper is not being invoked from Filter class
I have one Jersey(version 1.19) Exception Mapper class to send custom error to rest client.
@Provider
class GenericExceptionMapper extends ExceptionMapper[Exception] {
private val logger = ...
0
votes
1
answer
17
views
Guice inject resolution with multiple implementation to type
i have a situation where there two bindings with two different annotations for a type available
bind(MyType.class).annotatedWith(X.class).toInstance(XMyTypeImpl.class)
bind(MyType.class).annotatedWith(...
0
votes
1
answer
32
views
Get all instances created by Guice Provider
Assuming a ClassX as:
class ClassX {
int value;
ClassX() {
this.value = new Random().nextInt(10);
}
//equals and hashCode depend on "value"
}
If I have a ...
0
votes
0
answers
18
views
Understanding guice Modules.override()
I have an application module which installs various other modules.
public void bind(final Binder binder) {
binder.install(new ModuleA());
binder.install(new ModuleB());
binder.install(new ...
0
votes
1
answer
47
views
Map binding of generic factories
Suppose we have a couple of Shape implementations. Each implementation is created by a ShapeFactory from a corresponding ShapeConfig.
interface Shape {}
class Circle implements Shape {}
class Square ...
0
votes
1
answer
36
views
Simplest way to override an endpoint in google guice when writing functional tests
I have an application module that installs a DynamoDB module
install(new DynamoDBModule());
In DynamoDBModule we have some code to build the DynamoDb client and initialize the mapper
AmazonDynamoDB ...
0
votes
1
answer
35
views
Does Guice have an annotation similar to Spring's @Mandatory or @Required?
Guice does not require initialization of provides methods in the modules, allowing the service to start running without these consumers initializing, which can result in major issues after an outage.
...
1
vote
1
answer
55
views
Java : io.protostuff.compiler.parser.ParserException: Can not load proto
I am using guice parser to parse proto file. It is not able to resolve imports. Any suggestions experts in how to resolve imports public as well as imports within same project ?
Proto file
syntax = &...
0
votes
1
answer
84
views
How to mock an object with Guice @Inject?
I have a class A and a class B.
public class A{
@Inject // Guice Inject
private B b;
}
The test class looks like -
public class ATest{
private B b;
private A a;
@Before
...
0
votes
2
answers
44
views
Conditionally instantiating classes that use @Inject
I'm trying to understand how to handle conditionally creating new instances of a class that uses @Inject. In the below example I have a factory that instantiates classes based on a parameter.
...
0
votes
1
answer
46
views
How to create single object in extension and injection
I have the following class
@ExtendWith({SomeExtension.class})
public class Test{
@Inject
private User user
//some code
}
The code of SomeExtension class
public class SomeExtension implements ...
0
votes
0
answers
21
views
How to map the standard JSP Servlet URL patterns and a JSP page in Google Guice
I have translated nearly all of my traditional web.xml over to using Google Guice's to benefit from dependency injection.
Is there a way to configure the following in the Servlet Listener rather than ...
0
votes
1
answer
35
views
How to share the same dependency injection container in TestNG with guice
I run multiple TestNG 7.4.0 suites in parallel using something like (follows kotlin code, but it is the same in java, there is no language dependency):
val testNG = TestNG()
with(testNG) {
...
0
votes
0
answers
99
views
Integrating Google Guice support into a custom Java framework
So after a lot of searching and banging my head against a brick wall, I figured it was easier to put this question out there to see if anyone can help.
To set the backstory to this question:
I'm ...
0
votes
1
answer
97
views
Guice/MissingImplementation]: No implementation for ActorRef<UserParentActor$Create> was bound
I'm trying to create an actor in Java Play Framework (2.8.x) for webSocket. When my application runs, however, I get the error Guice/MissingImplementation]: No implementation for ActorRef<...
1
vote
2
answers
66
views
What is a right design for a such injection?
I have two classes of a one interface:
interface TimeUtils { ... }
class TimeUtilsImpl : TimeUtils { ... }
class TimeUtilsSimulation : TimeUtils { ... }
TimeUtils binding is in the module A:
bind(...
0
votes
1
answer
23
views
Get a wildcard instance from Google Guice
Hi I am experimenting with Google Guice 5.x. I have my class defined as:
public class Foo<T> {
// some logic here
}
and it's being used in other classes like:
public class Bar {
...
0
votes
0
answers
48
views
Best practice for passing data defined in a java annotation
I'm currently working on a java application that uses quartz to schedule some repeating jobs. I have some module and builder classes (based on guartz http://99soft.github.io/guartz/index.html) that ...
0
votes
0
answers
55
views
Cron Expression With Complex Timing
I have a java application using quartz that needs to run a job at different intervals over the course of the day. It should run every 30 minutes between 8AM and 4PM, skip 4PM to 6PM, and then run ...
0
votes
1
answer
131
views
Spigot with Guice gives NoClassDefFoundError on internal.Messages$FormatOptions
I've been playing around with Guice and stumbled upon this error that doesn't seem to make a lot of sense to me. It seems like whenever an error occurs during injection, Guice fails to properly log ...
0
votes
2
answers
58
views
How do I represent static constants that are derived at run time?
I have senderA and senderB both implementing sender and both singletons, and I have a SenderWrapper (which could possibly implement an ISenderWrapper) class where I want to represent SenderA and ...
0
votes
0
answers
43
views
Equivalent of Guice's MapBinder for Guava Table
For a normal Map, you can setup binding in Guice like this
MapBinder<K, V> mapBinder = MapBinder.newMapBinder(binder(), K.class, V.class);
mapBinder.addBinding(key).to(V.class);
Is there an ...
0
votes
1
answer
36
views
How To Load and Read Configuration in the Play Framework Guice Module
Problem:
I understand we can inject the Configuration module in the rest of the Play framework app, but I want to get my appliciation.conf information during the module configuration time. How can I ...
0
votes
0
answers
27
views
Guice interceptor binding in multithreading
I am binding an interceptor to the annotation defined in the module class -
bindInterceptor(Matchers.any(), Matchers.annotatedWith(Annotation.class), new NotNullInterceptor());
But I am using this ...
-1
votes
1
answer
271
views
Quartz Scheduler in Ktor-Kotlin runs on all the pods of Kubernetes cluster
I am new to Quartz and I am using Quartz 2.3.2 in KTOR application.
This application will run in the cluster using Kubernetes deployment.
My requirement is to run a scheduler in only one instance/pod ...
0
votes
2
answers
56
views
Guice inject cached or non-cached implementation
I have an application with guice but without spring.
I have:
public interface Service {
int square(int i);
}
And i have 2 implementations:
public class NormalService implements Service {
@...
1
vote
1
answer
50
views
Guice generic type injection
Lets say I have a generic class as follows:
public class Base<T extends Stoppable> {
protected final Injector injector;
protected T stoppable;
public Base(Module... module) {
...