Java - automatic implementation of a service locator pattern using annotations

Spring almost provides what I want. In Spring, you can simply annotate classes with @Component, and then use "context: component-scan" to let Spring automatically search for components. Then you can create the application context and call getBean (String, Class) to get an implementation of any interface or class.

For example, if I have the "Mp3Service" interface and I want to register a new implementation called "InternetMp3Service", all I have to do is add the @Component annotation to the class definition.

The only problem with this for me is that I want to use all this in the applet, and therefore get the java.lang.RuntimePermission exception to resolve "accessDeclaredMembers". I do not want to sign the applet, and I do not want to create an explicit configuration for beans.

What I'm looking for is a structure / library that will go through the annotations at the time of compilation / assembly and create a configuration that can then be read at runtime.

For example, if nothing happens here, and I decided it was worth it, I could write my own program to drop all classes and look for a specific annotation, and then create a Spring xml configuration file. However, I thought that someone might now have something already available.

Thank.

+5
1

, , . :

a) API . , Spring , , , .

b) , , Spring ( org.springframework.context.annotation.ComponentScanBeanDefinitionParser, , ). maven ant, . , , , Service Locator .

+2

All Articles