I’m using apache commons validator in few classes in my project, and I want to inject the singleton to my Class.
to use the validator you need to get the instance of the singleton like this:
// Get an EmailValidator
EmailValidator validator = EmailValidator.getInstance();
My question is how exactly could I inject the EmailValidator class to my project with annotations. I didn’t find any reference about these sort of things…
Declare the EmailValidator bean in the Spring XML and tell Spring to use a static factory method to instantiate it. See http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/beans.html#beans-factory-class-static-factory-method.
Or create a Spring bean implementing
FactoryBean<EmailValidator>. See http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/beans.html#beans-factory-extension-factorybean.