TUSCANY-4069: Apply patch from Rashmi Hunt to fix Issue with resolving autowired reference when binding is not defined to a target service exposed over multiple bindings

git-svn-id: https://svn.apache.org/repos/asf/tuscany/sca-java-2.x/trunk@1381971 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java b/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
index 647cd12..4ce163f 100644
--- a/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
+++ b/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
@@ -493,6 +493,16 @@
                     }
                 }
             } 
+            
+            // TUSCANY-4069 if no binding specified on reference then use service binding.sca if that exists 
+            if (endpointReference.getBinding() == null && endpointReference.getReference().getAutowire() == true){
+                for (Endpoint endpoint : matchedEndpoints){
+                    if (endpoint.getBinding() instanceof SCABinding){
+                        matchedEndpoint = endpoint;
+                        break;
+                    }
+                }
+            } 
 
             if (matchedEndpoint == null) {
                 // just take the first matched endpoint from the list