Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
methodInterceptor not resolving it dependencies
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  15 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
transmeta01  
View profile  
 More options Nov 15 2012, 9:13 pm
From: transmeta01 <transmet...@gmail.com>
Date: Thu, 15 Nov 2012 18:13:32 -0800 (PST)
Local: Thurs, Nov 15 2012 9:13 pm
Subject: methodInterceptor not resolving it dependencies

I have a method interceptor that has a number of dependencies (all guice
managed objects), as explained
in http://code.google.com/p/google-guice/wiki/AOP
the use of requestInjection should have guice inject the dependencies
auto-magically. But, when the interceptor is called, all the dependencies
are null. In my case, all dependencies are in the default scope, so I doubt
the problem to be a scoping issue. I did a google  and a StackOverflow
search, but no case seems to be such as mine...maybe is binding out of
order issue...if such thing exist. Any recommendations on who to approach
this problem?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stephan Classen  
View profile  
 More options Nov 16 2012, 2:41 am
From: Stephan Classen <st.clas...@gmx.ch>
Date: Fri, 16 Nov 2012 08:41:04 +0100
Local: Fri, Nov 16 2012 2:41 am
Subject: Re: methodInterceptor not resolving it dependencies
how about posting your interceptor code so we can have a look at it?

On 11/16/2012 03:13 AM, transmeta01 wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Fred Faber  
View profile  
 More options Nov 15 2012, 9:35 pm
From: Fred Faber <ffa...@gmail.com>
Date: Thu, 15 Nov 2012 21:35:52 -0500
Local: Thurs, Nov 15 2012 9:35 pm
Subject: Re: methodInterceptor not resolving it dependencies

It'd be helpful if you posted some code, such as where you request
injection and what the interceptor looks like.
On Nov 15, 2012 9:13 PM, "transmeta01" <transmet...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Mutezintare  
View profile  
 More options Nov 16 2012, 10:33 am
From: Richard Mutezintare <transmet...@gmail.com>
Date: Fri, 16 Nov 2012 10:33:35 -0500
Local: Fri, Nov 16 2012 10:33 am
Subject: Re: methodInterceptor not resolving it dependencies

here is the methodInterceptor:
public class AuditServiceImpl implements AuditService, MethodInterceptor {
 private AuditDao auditDao;
private PilotStatusDao pilotStatusDao;
private NoteStatusDao noteStatusDao;
private UserService userService;
private SectorService sectorService;
 public AuditServiceImpl() {}
 @Inject
public AuditServiceImpl(AuditDao auditDao, PilotStatusDao pilotStatusDao,
NoteStatusDao noteStatusDao, SectorService sectorService) {
this.auditDao = auditDao;
this.pilotStatusDao = pilotStatusDao;
this.noteStatusDao = noteStatusDao;

}

@Override
@Transactional(rollbackOn = IllegalStateException.class)
public Object invoke(MethodInvocation invocation) throws Throwable {
Note modifiedNote = (Note) invocation.getArguments()[0];
 Audit audit = new Audit();
audit.setCreationDate(new Date())
.setLastModifiedDate(new Date())
.setNote(modifiedNote)
.setNoteTime(modifiedNote.getDate())
.setNoteText(modifiedNote.getNoteText())
.setSector(modifiedNote.getSector());
 User modifiedBy = (User) invocation.getArguments()[1];
audit.setModifiedBy(modifiedBy);
audit.setPilotStatus(modifiedNote.getPilotStatus());
audit.setNoteStatus(modifiedNote.getNoteStatus());
 auditDao.persist(audit);
 return invocation.proceed();

}

in the servletModule I have this binding :

AuditServiceImpl auditInterceptor = new AuditServiceImpl();
requestInjection(auditInterceptor); bindInterceptor(Matchers.any(),
Matchers.annotatedWith(AuditTrail.class), auditInterceptor);

and the AuditService interface looks like this:

@ImplementedBy(AuditServiceImpl.class)
public interface AuditService {
 List<Audit> findAuditBySector(Sector sector);
 List<Audit> findAuditByDateRange(Date start, Date end);
 List<Audit> findAuditByUser(User user);
List<Audit> findAuditByUser(Long userId);
List<Audit> findAuditByUsername(String username);
 List<Audit> findAuditByKeyword(String keyword);
List<Audit> findAuditByKeyword(String... keywords);
Audit saveAudit(Audit auditToSave);


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stuart McCulloch  
View profile  
 More options Nov 16 2012, 10:40 am
From: Stuart McCulloch <mccu...@gmail.com>
Date: Fri, 16 Nov 2012 15:40:32 +0000
Local: Fri, Nov 16 2012 10:40 am
Subject: Re: methodInterceptor not resolving it dependencies

On 16 Nov 2012, at 15:33, Richard Mutezintare wrote:

^ requestInjection can only perform setter or field injection, it cannot perform constructor injection because the object is already constructed. Your interceptor expects constructor injection, which is why you see null values.

Personally I would try to separate the interceptor into its own class, rather than conflate it with an actual service implementation. Then you would only need to @Inject the service you need to use in the interceptor (with @Inject on a field/setter) which would make the code cleaner and easier to maintain.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Mutezintare  
View profile  
 More options Nov 16 2012, 10:48 am
From: Richard Mutezintare <transmet...@gmail.com>
Date: Fri, 16 Nov 2012 10:48:18 -0500
Local: Fri, Nov 16 2012 10:48 am
Subject: Re: methodInterceptor not resolving it dependencies

Good point about separation of method interception and service
implementation... Tried field injection...didn't work, then tried method
injection...didn't work either. Here is the exception I am getting:

com.google.inject.CreationException: Guice creation errors:<|<|1) Error in
custom provider, java.lang.NullPointerException<|  while locating
com.google.inject.persist.jpa.JpaPersistService<|  while locating
javax.persistence.EntityManager<|    for parameter 0 at
com.nashen.dao.AuditDao.<init>(AuditDao.java:19)<|  while locating
com.nashen.dao.AuditDao<|    for parameter 0 at
com.nashen.service.audit.AuditServiceImpl.setAuditDao(AuditServiceImpl.java :123)<|
 at
com.nashen.integration.GuiceServletConfig$1.configureServlets(GuiceServletC onfig.java:65)<|Caused
by: java.lang.NullPointerException<|?at
com.google.inject.persist.jpa.JpaPersistService.begin(JpaPersistService.jav a:70)<|?at
com.google.inject.persist.jpa.JpaPersistService.get(JpaPersistService.java: 50)<|?at
com.google.inject.persist.jpa.JpaPersistService.get(JpaPersistService.java: 34)<|?at
com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.ja va:55)<|?at
com.google.inject.internal.SingleParameterInjector.inject(SingleParameterIn jector.java:38)<|?at
com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterIn jector.java:62)<|?at
com.google.inject.internal.ConstructorInjector.construct(ConstructorInjecto r.java:84)<|?at
com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBi ndingImpl.java:254)<|?at
com.google.inject.internal.SingleParameterInjector.inject(SingleParameterIn jector.java:38)<|?at
com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterIn jector.java:62)<|?at
com.google.inject.internal.SingleMethodInjector.inject(SingleMethodInjector .java:83)<|?at
com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjecto rImpl.java:110)<|?at
com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.j ava:75)<|?at
com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.j ava:73)<|?at
com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:102 4)<|?at
com.google.inject.internal.MembersInjectorImpl.injectAndNotify(MembersInjec torImpl.java:73)<|?at
com.google.inject.internal.Initializer$InjectableReference.get(Initializer. java:147)<|?at
com.google.inject.internal.Initializer.injectAll(Initializer.java:92)<|?at
com.google.inject.internal.InternalInjectorCreator.injectDynamically(Intern alInjectorCreator.java:173)<|?at
com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCr eator.java:109)<|?at
com.google.inject.Guice.createInjector(Guice.java:95)<|?at
com.google.inject.Guice.createInjector(Guice.java:83)<|?at
com.nashen.integration.GuiceServletConfig.getInjector(GuiceServletConfig.ja va:45)<|?at
com.google.inject.servlet.GuiceServletContextListener.contextInitialized(Gu iceServletContextListener.java:45)<|?at
org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(Cont extHandler.java:771)<|?at
org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(Serv letContextHandler.java:411)<|?at
org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler .java:763)<|?at
org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContext Handler.java:247)<|?at
org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1238 )<|?at
org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java :706)<|?at
org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:480)<|?at
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle. java:64)<|?at
org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardSt arter.java:39)<|?at
org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:186)<|? at
org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager .java:494)<|?at
org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:14 1)<|?at
org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAp pProvider.java:145)<|?at
org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(Scanning AppProvider.java:56)<|?at
org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:609)<|?at
org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:540)<|?at
org.eclipse.jetty.util.Scanner.scan(Scanner.java:403)<|?at
org.eclipse.jetty.util.Scanner.doStart(Scanner.java:337)<|?at
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle. java:64)<|?at
org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppP rovider.java:121)<|?at
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle. java:64)<|?at
org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManag er.java:555)<|?at
org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:2 30)<|?at
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle. java:64)<|?at
org.eclipse.jetty.util.component.AggregateLifeCycle.doStart(AggregateLifeCy cle.java:81)<|?at
org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.ja va:58)<|?at
org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java :96)<|?at
org.eclipse.jetty.server.Server.doStart(Server.java:277)<|?at
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle. java:64)<|?at
org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1265)<|? at
java.security.AccessController.doPrivileged(Native Method)<|?at
org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1188)<|?a t
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<|?at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:3 9)<|?at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp l.java:25)<|?at
java.lang.reflect.Method.invoke(Method.java:597)<|?at
org.eclipse.jetty.start.Main.invokeMain(Main.java:468)<|?at
org.eclipse.jetty.start.Main.start(Main.java:616)<|?at
org.eclipse.jetty.start.Main.main(Main.java:92)<|<|2) Error in custom
provider, java.lang.NullPointerException<|  while locating
com.google.inject.persist.jpa.JpaPersistService<|  while locating
javax.persistence.EntityManager<|    for parameter 0 at
com.nashen.dao.PilotStatusDao.<init>(PilotStatusDao.java:14)<|  while
locating com.nashen.dao.PilotStatusDao<|    for parameter 0 at
com.nashen.service.audit.AuditServiceImpl.setPilotStatusDao(AuditServiceImp l.java:132)<|
 at
com.nashen.integration.GuiceServletConfig$1.configureServlets(GuiceServletC onfig.java:65)<|Caused
by: java.lang.NullPointerException<|?at
com.google.inject.persist.jpa.JpaPersistService.begin(JpaPersistService.jav a:70)<|?at
com.google.inject.persist.jpa.JpaPersistService.get(JpaPersistService.java: 50)<|?at
com.google.inject.persist.jpa.JpaPersistService.get(JpaPersistService.java: 34)<|?at
com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.ja va:55)<|?at
com.google.inject.internal.SingleParameterInjector.inject(SingleParameterIn jector.java:38)<|?at
com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterIn jector.java:62)<|?at
com.google.inject.internal.ConstructorInjector.construct(ConstructorInjecto r.java:84)<|?at
com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBi ndingImpl.java:254)<|?at
com.google.inject.internal.SingleParameterInjector.inject(SingleParameterIn jector.java:38)<|?at
com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterIn jector.java:62)<|?at
com.google.inject.internal.SingleMethodInjector.inject(SingleMethodInjector .java:83)<|?at
com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjecto rImpl.java:110)<|?at
com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.j ava:75)<|?at
com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.j ava:73)<|?at
com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:102 4)<|?at
com.google.inject.internal.MembersInjectorImpl.injectAndNotify(MembersInjec torImpl.java:73)<|?at
com.google.inject.internal.Initializer$InjectableReference.get(Initializer. java:147)<|?at
com.google.inject.internal.Initializer.injectAll(Initializer.java:92)<|?at
com.google.inject.internal.InternalInjectorCreator.injectDynamically(Intern alInjectorCreator.java:173)<|?at
com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCr eator.java:109)<|?at
com.google.inject.Guice.createInjector(Guice.java:95)<|?at
com.google.inject.Guice.createInjector(Guice.java:83)<|?at
com.nashen.integration.GuiceServletConfig.getInjector(GuiceServletConfig.ja va:45)<|?at
com.google.inject.servlet.GuiceServletContextListener.contextInitialized(Gu iceServletContextListener.java:45)<|?at
org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(Cont extHandler.java:771)<|?at
org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(Serv letContextHandler.java:411)<|?at
org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler .java:763)<|?at
org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContext Handler.java:247)<|?at
org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1238 )<|?at
org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java :706)<|?at
org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:480)<|?at
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle. java:64)<|?at
org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardSt arter.java:39)<|?at
org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:186)<|? at
org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager .java:494)<|?at ...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stuart McCulloch  
View profile  
 More options Nov 16 2012, 11:19 am
From: Stuart McCulloch <mccu...@gmail.com>
Date: Fri, 16 Nov 2012 16:19:40 +0000
Local: Fri, Nov 16 2012 11:19 am
Subject: Re: methodInterceptor not resolving it dependencies

On 16 Nov 2012, at 15:48, Richard Mutezintare wrote:

> Good point about separation of method interception and service implementation...

Another reason to separate them is the fact that you're using the manually new'd instance as the interceptor, but also have the implementation registered with an implicit @ImplementedBy binding. The implicit binding would create a separate instance whenever someone injected AuditService (assuming you didn't explicitly bind your new'd instance to AuditService). Not an issue here, but it could be in the future if someone decided to mark it this class as a @Singleton and wondered why they saw two instances being created - one via new and the other via Guice.

> Tried field injection...didn't work, then tried method injection...didn't work either. Here is the exception I am getting:

It looks as though the PersistService has not been started at the time the DAOs are being injected into the interceptor.

How are you starting the persist service - are you using an initializer class or the web PersistFilter?  http://code.google.com/p/google-guice/wiki/JPA

You could create a simple initializer, such as:

        public class PersistServiceInitializer {
                @Inject PersistServiceInitializer(PersistService service) {
                        service.start();
                }
        }

and then bind it as an eager singleton before the requestInjection line, which should ensure the PersistService is started before the interceptor is injected.

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Mutezintare  
View profile  
 More options Nov 16 2012, 11:25 am
From: Richard Mutezintare <transmet...@gmail.com>
Date: Fri, 16 Nov 2012 11:25:42 -0500
Local: Fri, Nov 16 2012 11:25 am
Subject: Re: methodInterceptor not resolving it dependencies

here is my complete configuration :
return Guice.createInjector(Stage.DEVELOPMENT,
new JerseyServletModule() {
@Override
protected void configureServlets() {
// AbstractMatcher<TypeLiteral<?>> matcher = new
AbstractMatcher<TypeLiteral<?>>() {
// public boolean matches(TypeLiteral<?> type) {
// return (type.getRawType().equals(LogbookService.class));
// }
// };
//
// bindListener(matcher, new LogbookServiceListener());

bind(UserResource.class);
bind(NoteResource.class);
bind(AuditResource.class);
bind(SectorResource.class);
bind(PilotStatusResource.class);

AuditServiceImpl auditInterceptor = new AuditServiceImpl();
requestInjection(auditInterceptor);
bindInterceptor(Matchers.any(), Matchers.annotatedWith(AuditTrail.class),
auditInterceptor);

AuthorizationService authorizationService = new AuthorizationService();
requestInjection(authorizationService);
bindInterceptor(Matchers.any(), Matchers.annotatedWith(RequiresRole.class),
authorizationService);

EntityNotFoundInterptor entityNotfound = new EntityNotFoundInterptor();
bindInterceptor(Matchers.any(), Matchers.annotatedWith(NullEntity.class),
entityNotfound);

filter("/rest/*").through(PersistFilter.class);

// init rest service
serve("/rest/*").with(GuiceContainer.class, params);
binder().bind(GuiceContainer.class).asEagerSingleton();

}
}, new JpaPersistModule("logbook-persistence"));

the JpaPersistModule is instantiated after the requestInjection call...I am
looking at ways to use some kind of deferred binding...perhaps using a
Provider<T>...Not sure if that would solve my issue though...Any
recommendations?

On Fri, Nov 16, 2012 at 11:19 AM, Stuart McCulloch <mccu...@gmail.com>wrote:

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stuart McCulloch  
View profile  
 More options Nov 16 2012, 11:44 am
From: Stuart McCulloch <mccu...@gmail.com>
Date: Fri, 16 Nov 2012 16:43:56 +0000
Local: Fri, Nov 16 2012 11:43 am
Subject: Re: methodInterceptor not resolving it dependencies

On 16 Nov 2012, at 16:25, Richard Mutezintare wrote:

Yes, injecting a Provider for the DAO into the interceptor will help defer use of the PersistService until you actually need it.

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Mutezintare  
View profile  
 More options Nov 16 2012, 11:52 am
From: Richard Mutezintare <transmet...@gmail.com>
Date: Fri, 16 Nov 2012 11:52:55 -0500
Local: Fri, Nov 16 2012 11:52 am
Subject: Re: methodInterceptor not resolving it dependencies

There is still a problem: how do I construct the DAO object in the
provider? It has a guice managed dependencie (the EntityManager)? What is
the simplest or elegant way of doing it?

On Fri, Nov 16, 2012 at 11:43 AM, Stuart McCulloch <mccu...@gmail.com>wrote:

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stuart McCulloch  
View profile  
 More options Nov 16 2012, 11:59 am
From: Stuart McCulloch <mccu...@gmail.com>
Date: Fri, 16 Nov 2012 16:59:21 +0000
Local: Fri, Nov 16 2012 11:59 am
Subject: Re: methodInterceptor not resolving it dependencies

On 16 Nov 2012, at 16:52, Richard Mutezintare wrote:

> There is still a problem: how do I construct the DAO object in the provider? It has a guice managed dependencie (the EntityManager)? What is the simplest or elegant way of doing it?

Just change:

   @Inject AuditDao auditDao;

into:

   @Inject Provider<AuditDao> auditDaoProvider;

and then use auditDaoProvider.get() to get the DAO.

http://code.google.com/p/google-guice/wiki/InjectingProviders

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Mutezintare  
View profile  
 More options Nov 16 2012, 12:13 pm
From: Richard Mutezintare <transmet...@gmail.com>
Date: Fri, 16 Nov 2012 12:12:59 -0500
Local: Fri, Nov 16 2012 12:12 pm
Subject: Re: methodInterceptor not resolving it dependencies

ok so now I have:

public class AuditDaoProvider implements Provider<AuditDao> {

AuditDao _auditDao;
 @Inject
public AuditDaoProvider(AuditDao auditDao) {
_auditDao = auditDao;

}

 @Override
public AuditDao get() {
return _auditDao;

}

and in the method interceptor I have:
@Inject private Provider<AuditDao> _auditDaoProvider;
public AuditServiceImpl(Provider<AuditDao> auditDaoProvider) {
_auditDaoProvider = auditDaoProvider;

}

... and when I need the DAO, I do: _auditDaoProvider.get().persist(audit);

it seems a binding of the provider is missing in the servletModule
config...or it is not necessary to explicitly bind the provider?

On Fri, Nov 16, 2012 at 11:59 AM, Stuart McCulloch <mccu...@gmail.com>wrote:

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Mutezintare  
View profile  
 More options Nov 16 2012, 12:18 pm
From: Richard Mutezintare <transmet...@gmail.com>
Date: Fri, 16 Nov 2012 12:18:03 -0500
Local: Fri, Nov 16 2012 12:18 pm
Subject: Re: methodInterceptor not resolving it dependencies

seems no explicit binding of the provider is necessary....works like a
charm not...Thanks Stuart!

On Fri, Nov 16, 2012 at 12:12 PM, Richard Mutezintare <transmet...@gmail.com

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stuart McCulloch  
View profile  
 More options Nov 16 2012, 12:23 pm
From: Stuart McCulloch <mccu...@gmail.com>
Date: Fri, 16 Nov 2012 17:22:52 +0000
Local: Fri, Nov 16 2012 12:22 pm
Subject: Re: methodInterceptor not resolving it dependencies

On 16 Nov 2012, at 17:12, Richard Mutezintare wrote:

> ok so now I have:

>    public class AuditDaoProvider implements Provider<AuditDao> {

>    AuditDao _auditDao;

>    @Inject
>    public AuditDaoProvider(AuditDao auditDao) {
>            _auditDao = auditDao;
>    }

>    @Override
>    public AuditDao get() {
>            return _auditDao;
>    }

^ Remove the AuditDaoProvider class completely, you don't need it.

If Foo exists as a binding then you can @Inject Provider<Foo> without any change because Provider<T> is a built-in binding:

   http://code.google.com/p/google-guice/wiki/BuiltInBindings

Also the AuditDaoProvider class won't work because you're injecting AuditDao into the constructor, which means it's not lazily loaded (and it also introduces a cycle).

> and in the method interceptor I have:
> @Inject private Provider<AuditDao> _auditDaoProvider;
> public AuditServiceImpl(Provider<AuditDao> auditDaoProvider) {
>            _auditDaoProvider = auditDaoProvider;
>    }

> ... and when I need the DAO, I do: _auditDaoProvider.get().persist(audit);

> it seems a binding of the provider is missing in the servletModule config...or it is not necessary to explicitly bind the provider?

If you use the built-in Provider<AuditDao> binding to lazy load AuditDao then you don't need to explicitly bind a provider.

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Mutezintare  
View profile  
 More options Nov 16 2012, 12:30 pm
From: Richard Mutezintare <transmet...@gmail.com>
Date: Fri, 16 Nov 2012 12:30:00 -0500
Subject: Re: methodInterceptor not resolving it dependencies

it works as described above...DAO instance is not null.

On Fri, Nov 16, 2012 at 12:22 PM, Stuart McCulloch <mccu...@gmail.com>wrote:

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »