#如题,背景如下:我目前处于处于软件实施这个岗位,平时会用 python 处理一些数据。所以,对 java 理解甚少。公司的各个系统是用 dubbo 连接各个服务的。但 python 没有可以调 dubbo 协议接口的库,所以我想通过 jshell 来调用 dubbo 接口。 #测试使用的是dubbo 示例中的 dubbo-samples-protobuf ,我把服务和客户端分别放在两台机器上,用 maven 编译测试成功后。把 traget 文件夹下 lib 里的 jar 包复制到 jshell 自定义的 class 文件夹里。然后用 jshell 进行测试,代码如下
import org.springframework.context.support.ClassPathXmlApplicationContext;
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("file:/home/dubbo-consumer.xml");
context.start();
以上代码片段没有报错,接着输入下面代码,回车测试
context.getBean("demoService")
然后报错了:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'demoService': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: org.apache.dubbo.demo.DemoService
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:177)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1640)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:254)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1080)
at .(#27:1)
然后换成下方代码,再运行同样报错:
public interface DemoService {
String sayHello(String name);
};
public class DemoServiceImpl implements DemoService {
public String sayHello(String name) {
return "Hello " + name;
}
};
DemoService demoService = (DemoService)context.getBean("demoService");
#恳请广大 V 友告知这是为啥报错呢?如果我想用 jshell 来调用 dubbo 远程服务接口,该怎么办呢?
版本为jdk10,以下为xml配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
<dubbo:application name="demo-consumer"/>
<dubbo:registry address="zookeeper://192.168.1.122:2181" timeout="8000"/>
<dubbo:reference id="demoService" check="false" interface="org.apache.dubbo.demo.DemoService"/>
</beans>
同样的配置用教程编译出来的jar文件来运行是可以的
1
873792861 OP 补充一点,用的是 jdk10
|
2
putaozhenhaochi 2022-07-16 13:15:50 +08:00 via Android
配置文件贴出来
|
3
putaozhenhaochi 2022-07-16 13:20:23 +08:00 via Android
|
4
873792861 OP @putaozhenhaochi 已经补充
|
5
Kaiv2 2022-07-16 15:30:08 +08:00
|
6
873792861 OP @putaozhenhaochi 这个不适合,也不管用
|
7
kkkiio 2022-07-17 10:33:03 +08:00 via iPhone
Spring Shell 也许能解决你的问题
|