On 16 Nov 2012, at 15:33, Richard Mutezintare wrote:
> 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);
^ 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.
> 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);
>
>
> }
>
>
> On Thu, Nov 15, 2012 at 9:35 PM, Fred Faber <[email protected]> wrote:
> 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" <[email protected]> wrote:
> 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 received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-guice/-/Jki7NswRYUwJ.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-guice?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-guice?hl=en.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-guice?hl=en.
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.