日期 2022-10-13
选取服务端核心关键部分
main 函数中
ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("provider.xml");
context.start();
provider.xml 中 端口8005
<dubbo:registry address="N/A" />
<dubbo:protocol port="8005" name="dubbo" accesslog="true">
<dubbo:service
interface="com.www.service.ProviderService"
ref="ProviderService"
version="1.0.0"
timeout="3000">
</dubbo:service>
<!--Bean bean定义-->
<bean id="ProviderService" class="com.www.service.ProviderServiceImpl"/>
public interface ProviderService {
String SayHello(String word);
}
public class ProviderServiceImpl implements ProviderService{
@Override
public String SayHello(String word) {
System.out.println("server:"+word);
return "server return:"+word;
}
}
pom 中添加
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.6.6</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.32.Final</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>2.8.0</version>
</dependency>
启动main 函数就可以了