老师 consumerClient请求不到provider里面的ServiceAPI呀
来源:2-3 Spring的直连提供者

weixin_慕用7362611
2020-01-07
首先启动Provider:
其次启动Consumer:
也没有问题。
然后输入MOOC就出现问题了:
mooc
Exception in thread “main” org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘consumerService’: FactoryBean threw exception on object creation; nested exception is com.alibaba.dubbo.rpc.RpcException: Fail to create remoting client for service(dubbo://localhost:20880/org.greenarrow.ServiceAPI?application=demo-consumer&codec=dubbo&dubbo=2.5.3&heartbeat=60000&interface=org.greenarrow.ServiceAPI&methods=sendMessage&pid=8894&side=consumer×tamp=1578380320391): client(url: dubbo://localhost:20880/org.greenarrow.ServiceAPI?application=demo-consumer&codec=dubbo&dubbo=2.5.3&heartbeat=60000&interface=org.greenarrow.ServiceAPI&methods=sendMessage&pid=8894&side=consumer×tamp=1578380320391) failed to connect to server localhost/127.0.0.1:20880, error message is:connection timed out: /125.211.213.133:20880
at org.springframework.beans.factory.support.FactoryBeanRegistrySupportKaTeX parse error: Expected 'EOF', got '&' at position 1154: …n=demo-consumer&̲codec=dubbo&dub…Adpative.refer(Protocol$Adpative.java)
at com.alibaba.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:392)
at com.alibaba.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:300)
at com.alibaba.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:138)
at com.alibaba.dubbo.config.spring.ReferenceBean.getObject(ReferenceBean.java:65)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupportKaTeX parse error: Expected 'EOF', got '&' at position 200: …n=demo-consumer&̲codec=dubbo&dub…Adpative.connect(Transporter$Adpative.java)
at com.alibaba.dubbo.remoting.Transporters.connect(Transporters.java:67)
at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchanger.connect(HeaderExchanger.java:37)
at com.alibaba.dubbo.remoting.exchange.Exchangers.connect(Exchangers.java:102)
at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol.initClient(DubboProtocol.java:378)
… 20 more
Caused by: org.jboss.netty.channel.ConnectTimeoutException: connection timed out: /125.211.213.133:20880
at org.jboss.netty.channel.socket.nio.NioClientBoss.processConnectTimeout(NioClientBoss.java:139)
at org.jboss.netty.channel.socket.nio.NioClientBoss.process(NioClientBoss.java:83)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:337)
at org.jboss.netty.channel.socket.nio.NioClientBoss.run(NioClientBoss.java:42)
at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
at org.jboss.netty.util.internal.DeadLockProofWorker1.run(DeadLockProofWorker.java:42)atjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)atjava.util.concurrent.ThreadPoolExecutor1.run(DeadLockProofWorker.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor1.run(DeadLockProofWorker.java:42)atjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)atjava.util.concurrent.ThreadPoolExecutorWorker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
反正就是找不到Provider的bean。这句是关键**Fail to create remoting client for service(dubbo://localhost:20880/org.greenarrow.ServiceAPI?application=demo-consumer&codec=dubbo&dubbo=2.5.3&heartbeat=60000&interface=org.greenarrow.ServiceAPI&methods=sendMessage&pid=8894&side=consumer×tamp=1578380320391): client(url: dubbo://localhost:20880/org.greenarrow.ServiceAPI?application=demo-consumer&codec=dubbo&dubbo=2.5.3&heartbeat=60000&interface=org.greenarrow.ServiceAPI&methods=sendMessage&pid=8894&side=consumer×tamp=1578380320391) failed to connect to server localhost/127.0.0.1:20880, error message is:connection timed out: /125.211.213.133:20880
**
然后我的Provider:
public class ProviderClient {
public static void main(String[] args) throws IOException {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-hello-provider.xml");
ServiceAPI serviceAPI = (ServiceAPI)context.getBean("providerService");
context.start();
System.in.read();
}
}
consumer:
public class ConsumerClient {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-hello-consumer.xml");
context.start();
while (true){
Scanner scanner = new Scanner(System.in);
String message = scanner.next();
//获取接口
ServiceAPI serviceAPI = (ServiceAPI)context.getBean("consumerService");
System.out.println(serviceAPI.sendMessage(message));
}
}
}
applicationContext-hello-consumer.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
"
>
<!-- consumer's application name, used for tracing dependency relationship (not a matching criterion),
don't set it same as provider -->
<dubbo:application name="demo-consumer"/>
<!-- generate proxy for the remote service, then demoService can be used in the same way as the
local regular interface -->
<dubbo:reference
id="consumerService"
interface="org.greenarrow.ServiceAPI"
url="dubbo://localhost:20880"
/>
</beans>
applicationContext-hello-provider.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
"
>
<!-- provider's application name, used for tracing dependency relationship -->
<dubbo:application name="demo-provider"/>
<!-- use dubbo protocol to export service on port 20880 -->
<dubbo:protocol name="dubbo" port="20880"/>
<!-- service implementation, as same as regular local bean -->
<bean id="providerService" class="org.greenarrow.quickstart.QuickStartServiceImpl"/>
<!-- declare the service interface to be exported -->
<dubbo:service
registry="N/A"
interface="org.greenarrow.ServiceAPI"
ref="providerService"/>
</beans>
老师救命啊
1回答
-
weixin_慕用7362611
提问者
2020-01-07
我关掉重启一次idea就OK了,这是为什么?老师帮帮我,要不下次又碰到就凉了
012020-01-09
相似问题