0

I have a spring application that uses rabbitmq-based RPCs. on the client side, I would like to generate a proxy object that delegates to the RPC based on annotated interfaces available on the classpath of the client. in a similar way, I want to be able to register exchanges, queues and consumers on the server side, based on annotated concrete classes.

the annotations i have are @RpcInterface and @RpcEndpoint, and I created a java proxy from the interfaces implemented by the RpcEndpoint.

My problem now is that I want to be able to scan the classpath for classes with these annotations and add beans for client- and server side to the application context based on that. The problem is that FactoryBean only allows instantiation of a single object, and BeanDefinitionRegistryPostProcessor requires me to add bean definitions, which isn't really possible, because on the client side, I might only have interface that cannot be instantiated.

Right now, I'm adding @Configuration classes with one @Beans method for each interface next to where the interfaces are defined, so if I add a dependency on the interface, i would also pull in the @Configuration. This feels like unnecessary code, if I could just have something that returns a bunch of instantiated beans rather than one single bean.

so, instead of:

@Bean
public Object createBlahBean() {
    createProxyFor(MyInterface.class);
}

I would like to be able to do:

@Beans
public List<Object> createBlahBeans() {
    List<Object> out = new ArrayList<>();
    for(Class c : findAnnotatedInterfacesFromClasspath()) {
        out.add(createProxyFor(c));
    }
    return out;
}

or similar. any pointers?

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
rmalchow
  • 2,689
  • 18
  • 31
  • Use a `BeanDefinitionRegistryPostProcessor` which adds the `FactoryBean` to create the proxy. You don't need a concrete class for that. Also is there a reason why you cannot use [Springs remoting implementation with RabbitMQ](http://docs.spring.io/spring-amqp/reference/htmlsingle/#remoting)? – M. Deinum Aug 26 '15 at 09:25
  • hmm. because i didn't find it. i guess i am doing pretty much the same thing on foot. thanks! i'll look into that. – rmalchow Aug 26 '15 at 11:15

0 Answers0