@Autowired
注釈の動作を変更することはできないと思います。
ただし、独自のものを簡単に実装して、 、BeanPostProcessor
などのすべての便利な Spring クラスを使用できます。AnnotationUtils
ReflectionUtils
あるプロジェクトでは、カスタム JAX-WS ポート インジェクションが必要でした。@InjectedPort
そのため、アノテーションを作成して独自に実装しましたInjectedPortAnnotationBeanPostProcessor
(これはカスタム インジェクション ロジックの単純さを示しているだけであり、コード自体の目的は質問とは関係ありません)。
@Override
public Object postProcessBeforeInitialization(final Object bean, String beanName) {
// Walk through class fields and check InjectedPort annotation presence
ReflectionUtils.doWithFields(bean.getClass(), new FieldCallback() {
@Override
public void doWith(final Field field) {
// Find InjectedPort annotation
final InjectedPort injectedPort = field.getAnnotation(InjectedPort.class);
if (injectedPort == null) {
return; // Annotation is not present
}
// Get web service class from the annotation parameter
Class<?> serviceClass = injectedPort.value();
// Find web service annotation on the specified class
WebServiceClient serviceAnnotation = AnnotationUtils.findAnnotation(serviceClass, WebServiceClient.class);
if (serviceAnnotation == null) {
throw new IllegalStateException("Missing WebService " + "annotation on '" + serviceClass + "'.");
}
// Get web service instance from the bean factory
Service service = (Service) beanFactory.getBean(serviceClass);
// Determine the name of the JAX-WS port
QName portName = new QName(service.getServiceName().getNamespaceURI(), findPortLocalName(serviceClass, field.getType()));
// Obtain the JAX-WS port
Object port = service.getPort(portName, field.getType());
// Inject the port into the target bean
ReflectionUtils.makeAccessible(field);
ReflectionUtils.setField(field, bean, port);
}
});
return bean;
}