@@ -69,14 +69,11 @@ public <T> T getProxy(Invoker<T> invoker, boolean generic) throws RpcException {
6969
7070 Class <?> realInterfaceClass = null ;
7171 if (generic ) {
72- try {
73- // find the real interface from url
74- String realInterface = invoker .getUrl ().getParameter (Constants .INTERFACE );
75- realInterfaceClass = ReflectUtils .forName (classLoader , realInterface );
76- interfaces .add (realInterfaceClass );
77- } catch (Throwable e ) {
78- // ignore
79- }
72+ // In generic mode, ensure GenericService is the first interface so that
73+ // Spring bean type resolution treats the proxy as GenericService.
74+ // This prevents BeanNotOfRequiredTypeException when the real interface
75+ // class exists on the classpath and would otherwise take priority.
76+ interfaces .add (invoker .getInterface ());
8077
8178 if (GenericService .class .isAssignableFrom (invoker .getInterface ())
8279 && Dubbo2CompactUtils .isEnabled ()
@@ -90,6 +87,15 @@ public <T> T getProxy(Invoker<T> invoker, boolean generic) throws RpcException {
9087 interfaces .add (org .apache .dubbo .rpc .service .GenericService .class );
9188 }
9289 }
90+
91+ try {
92+ // find the real interface from url
93+ String realInterface = invoker .getUrl ().getParameter (Constants .INTERFACE );
94+ realInterfaceClass = ReflectUtils .forName (classLoader , realInterface );
95+ interfaces .add (realInterfaceClass );
96+ } catch (Throwable e ) {
97+ // ignore
98+ }
9399 }
94100
95101 interfaces .add (invoker .getInterface ());
0 commit comments