Guice module integration issue with REST
- Dominant language
- Java
- Stars
- 12.7k
- Forks
- 1.7k
- Avg merge
- 11m
- Merged PRs (30d)
- 2
Description
Guice module integration issue with REST I have define one AOP guice based module, but when I tried to integrate with REST code, methodInvocation.proceed retun null. What might be best way to solve this issue.
Define AOP Guice based module as below
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@interface NotOnWeekends {}
public class WeekendBlocker implements MethodInterceptor {
public Object invoke(MethodInvocation invocation) throws Throwable {
Calendar today = new GregorianCalendar();
if (today.getDisplayName(DAY_OF_WEEK, LONG, ENGLISH).startsWith("S")) {
throw new IllegalStateException(
invocation.getMethod().getName() + " not allowed on weekends!");
}
return invocation.proceed();
}
}
public class NotOnWeekendsModule extends AbstractModule {
protected void configure() {
bindInterceptor(Matchers.any(), Matchers.annotatedWith(NotOnWeekends.class),
new WeekendBlocker());
}
}
But I tried to Integrate this with my REST API
public class WorkerBean implements Worker {
@Autowired
private WorkerRepository workerRepository;
@Override
@NotOnWeekends
public Collection findAll() {
Collection workers = workerRepository.findAll();
return workers;
}
@RestController
public class WorkerController {
@RequestMapping(
value = "/api/workers",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity> getWorkers() {
Worker worker = Guice.createInjector(new NotOnWeekendsModule()).getInstance(Worker.class);
Collection worker = worker.findAll(); // return null
....
}
Contributor guide
Assessment
This issue has not been assessed yet.