I have some experience with guice and i just tried guice-persist. But now i get a very strange error in my very simple module. This is my module:
public class VotingModule extends AbstractModule {
@Override
protected void configure() {
bind(VotingService.class).to(VotingServiceImpl.class);
}
}
I created a factory (this is for using this api, there is no main) to get an instance of the service:
public static VotingService getService(final String persistenceUnit) {
// initialization of dependency injection
Injector i = Guice.createInjector(new JpaPersistModule(persistenceUnit), new VotingModule());
// Starts persistence stuff (jpa is ready now)
i.getInstance(PersistService.class).start();
return i.getInstance(VotingService.class);
}
The VotingService and its implementation encapsulate simple data-base interactions. For this "VotingServiceImpl" only injects an EntityManager and uses @Transactionl on some methods. So why i get
1) Unable to method intercept: com.prodyna.nabucco.groupware.voting.core.service.impl.VotingServiceImpl
at com.prodyna.nabucco.groupware.voting.core.service.impl.VotingModule.configure(VotingModule.java:10)
? The error is thrown on this simple test:
@Test
public void test(){
VotingService vs = VotingServiceFactory.getService();
}
Edit This error only occurs if bound implementation uses @Transactional. So something went wrong with aop stuff but how to fix it? Edit
Ok i found the problem after some hours of debugging: The problem was a private constructor in interface' implementation. For vanilla guice private constructors are fine (imho good practice - you can't use "new"). but AOP (Interceptors) doesn't work with private constructors.
I think there should be some hints in doc about that?!