I’m working on a Spring application using beans of different scopes. Many beans are singletons, other request or custom scoped. Especially using those custom scopes makes it sometimes difficult to find out which scope can be safely injected into which other scope or when e.g. a Provider<T> needs to be used. I am aware that I can just create scope
Tag: dependency-injection
Dagger Component has conflicting scopes
I am using Dagger and I have an app component with @Singleton scope and also a subcomponent with @Singleton scope. Now when I compile it I get this error: [io.droid.nowtellapp.dagger.SignInMvpComponet] io.droid.nowtellapp.dagger.SignInMvpComponet has conflicting scopes: io.droid.nowtellapp.dagger.ApplicationComponent also has @Singleton To resolve this error I removed @Singleton from my subcomponet and compiled it, this time getting this error: Error:(12, 1) error: io.droid.nowtellapp.dagger.SignInMvpComponet
java.lang.NoClassDefFoundError: com/google/inject/Module using Guice
I am trying to use the DI mechanism provided by Google, but when I run my application, I am getting the following error: The pom.xml file looks like: And the code where I am using it looks like: And I have imported com.google.inject.Guice and com.google.inject.Injector I have been checking for several places but I cannot see any relevant solution for
What exactly is Field Injection and how to avoid it?
I read in some posts about Spring MVC and Portlets that field injection is not recommended. As I understand it, field injection is when you inject a Bean with @Autowired like this: During my research I also read about constructor injection: What are the advantages and the disadvantages of both of these types of injections? EDIT 1: As this question
Why am I getting “classes must have either one (and only one) constructor” error?
I have been trying to get Guice working but end up with this: Classes must have either one (and only one) constructor My interface: The implementation: The binding module: The AddrBook client where I am injecting: And my main: After all this, I’m getting this error: I have experience with Spring and not with Guice. Where am I going wrong
Difference between @Bean and @Autowired
Why can’t I use @Autowired in this case? but can use @Bean Aren’t the two ways to generate BookingService the same thing? Answer @Bean and @Autowired do two very different things. The other answers here explain in a little more detail, but at a simpler level: @Bean tells Spring ‘here is an instance of this class, please keep hold of
Guice: Injecting map binding with @Named
I would like to have the following injection model. Is this possible with Guice? Module: Class: Answer That is not what map binder are intended for. In your example a binding annotation would be the way to go: https://github.com/google/guice/wiki/BindingAnnotations
my Google Guice method interceptor doesn’t execute but Why?
So I am testing a simple Google Guice interceptor – My Annotation – @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface AppOpsOperation { } My Interceptor public …
Can @Inject be made optional in JSR 330 (like @Autowire(required=false)?
Spring’s @Autowire can be configured such that Spring will not throw an error if no matching autowire candidates are found: @Autowire(required=false) Is there an equivalent JSR-330 annotation? @Inject always fails if there is no matching candidate. Is there any way I can use @Inject but not have the framework fail if no matching types are found? I haven’t been able
using Spring JdbcTemplate – injecting datasource vs jdbcTemplate
As per Spring documentation, the steps to use Spring JdbcTemplate is as follows: And then, Basically, the JdbcTemplate is created inside the Component class using the setter for datasource. Is there anything wrong with doing it this way instead so that there is exactly ONE instance of jdbcTemplate in the application? And then injecting the jdbcTemplate itself directly into the