<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8" ?>
public interface DemoService { String sayHello(String name);}
import com.example.springbootdubbo.service.DemoService;import org.apache.dubbo.rpc.RpcContext;import java.text.SimpleDateFormat;import java.util.Date;public class DemoServiceImpl implements DemoService { @Override public String sayHello(String name) { System.out.println("["+new SimpleDateFormat("HH:mm:ss").format(new Date()) +"] " + "Hello " + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress()); return "Hellot" + name + ",tresponse from provider:t" + RpcContext.getContext().getLocalAddress(); }}
服务提供方import org.springframework.context.support.ClassPathXmlApplicationContext;import java.util.concurrent.CountDownLatch;public class DemoProvider { public static void main(String[] args) throws InterruptedException { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("dubbo-provider.xml"); context.start(); System.out.println("dubbo service started"); new CountDownLatch(1).await(); }}
服务消费方import com.example.springbootdubbo.service.DemoService;import org.springframework.context.support.ClassPathXmlApplicationContext;public class DemoConsumer { public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("dubbo-consumer.xml"); context.start(); DemoService demoService = (DemoService) context.getBean("demoService"); String hello = demoService.sayHello("world"); System.out.println(hello); }}
本来是准备用spring直接搭dubbo的,但网上没找到spring5.x版本和dubbo的对应版本,就准备先用springboot和dubbo的搭配启起来后,再用对应的依赖版本整spring与dubbo的搭配,目前还是失败,先记录下,后续看问题所在
二月 03, 2022 9:19:22 上午 org.springframework.context.support.AbstractApplicationContext prepareRefresh信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@79fc0f2f: startup date [Thu Feb 03 09:19:22 CST 2022]; root of context hierarchyException in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/ErrorCodedat java.lang.ClassLoader.defineClass1(Native Method)at java.lang.ClassLoader.defineClass(ClassLoader.java:763)at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)at java.net.URLClassLoader.access$100(URLClassLoader.java:74)at java.net.URLClassLoader$1.run(URLClassLoader.java:369)at java.net.URLClassLoader$1.run(URLClassLoader.java:363)at java.security.AccessController.doPrivileged(Native Method)at java.net.URLClassLoader.findClass(URLClassLoader.java:362)at java.lang.ClassLoader.loadClass(ClassLoader.java:424)at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)at java.lang.ClassLoader.loadClass(ClassLoader.java:357)at java.lang.ClassLoader.defineClass1(Native Method)at java.lang.ClassLoader.defineClass(ClassLoader.java:763)at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)at java.net.URLClassLoader.access$100(URLClassLoader.java:74)at java.net.URLClassLoader$1.run(URLClassLoader.java:369)at java.net.URLClassLoader$1.run(URLClassLoader.java:363)at java.security.AccessController.doPrivileged(Native Method)at java.net.URLClassLoader.findClass(URLClassLoader.java:362)at java.lang.ClassLoader.loadClass(ClassLoader.java:424)at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)at java.lang.ClassLoader.loadClass(ClassLoader.java:357)at org.springframework.context.support.AbstractRefreshableApplicationContext.createBeanFactory(AbstractRefreshableApplicationContext.java:200)at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:126)at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:614)at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:515)at org.springframework.context.support.ClassPathXmlApplicationContext.