I have a custom annotation that is declared as a Spring managed Service:
@Service
public @interface MyServiceAnnotation {
// my service url
String url();
}
The above declaration enables my services to be autowired as Spring Managed beans.
@MyServiceAnnotation(url="/path/serviceLocation")
public class SomeService {
doWork();
}
However, there are certain services that have their bean definitions in an applicationContext.xml
. Adding the @MyServiceAnnotation
to such beans makes them both Autowiring enabled, as well as inject dependecy through the xml file.
Due to issues related to legacy code, I don't want to remove the xml bean definitions and make them all autowired.
So, is there a way in which I could turn off autowiring in this case, and still use @MyServiceAnnotation
? Ideally I would like to have the @Service
annotation on MyServiceAnnotation
, the existing services would still use the @MyServiceAnnotation
but would get their dependencies injected based on the xml. All the new services would be autowired without the xml bean definitions.
One possible approach is to create NonSpringManagedMyServiceAnnotation
that is same as MyServiceAnnotation
, but without the @Service
annotation on it. The downside of this is that I'd have to duplicate rest of the code from MyServiceAnnotation
, which I don't want to.