Przeglądaj źródła

增加IHelloService接口,但是无法执行。

huangbo 6 lat temu
rodzic
commit
cde1d68e75

+ 6 - 0
dubbo-example/dubbo-service-provider/src/main/java/com/ai/ipu/dubbo/provider/IHelloService.java

1
package com.ai.ipu.dubbo.provider;
2

3
public interface IHelloService {
4
    
5
    public String hello(String name);
6
}

+ 10 - 0
dubbo-example/dubbo-service-provider/src/main/java/com/ai/ipu/dubbo/provider/impl/HelloService.java

1
package com.ai.ipu.dubbo.provider.impl;
2

3
import com.ai.ipu.dubbo.provider.IHelloService;
4

5
public class HelloService implements IHelloService{
6

7
    public String hello(String name) {
8
        return "hello" + name;
9
    }
10
}

+ 3 - 0
dubbo-example/dubbo-service-provider/src/main/resources/dubbo-provider-simple.xml

28
    <!-- 服务注册配置 start=========================== -->
28
    <!-- 服务注册配置 start=========================== -->
29
    <dubbo:service interface="com.ai.ipu.dubbo.provider.HelloService" ref="helloService" token="true"/>
29
    <dubbo:service interface="com.ai.ipu.dubbo.provider.HelloService" ref="helloService" token="true"/>
30
    <bean id="helloService" class="com.ai.ipu.dubbo.provider.impl.HelloServiceImpl"/>
30
    <bean id="helloService" class="com.ai.ipu.dubbo.provider.impl.HelloServiceImpl"/>
31
    
32
    <dubbo:service interface="com.ai.ipu.dubbo.provider.IHelloService" ref="iHelloService" token="true"/>
33
    <bean id="iHelloService" class="com.ai.ipu.dubbo.provider.impl.HelloService"/>
31
    <!-- 服务注册配置 end =========================== -->
34
    <!-- 服务注册配置 end =========================== -->
32
</beans>
35
</beans>

+ 8 - 2
dubbo-example/dubbo-service-provider/src/test/java/com/ai/ipu/dubbo/provider/HelloServiceTest.java

1
package com.ai.ipu.dubbo.provider;
1
package com.ai.ipu.dubbo.provider;
2
2
3
3
4
import junit.framework.TestCase;
5
4
import org.springframework.context.support.ClassPathXmlApplicationContext;
6
import org.springframework.context.support.ClassPathXmlApplicationContext;
5
7
6
public class HelloServiceTest extends TestCase {
8
public class HelloServiceTest extends TestCase {
8
10
9
    @Override
11
    @Override
10
    protected void setUp() throws Exception {
12
    protected void setUp() throws Exception {
11
        // TODO Auto-generated method stub
12
        context = new ClassPathXmlApplicationContext(new String[] { DubboServiceProviderStart.DUBBO_CONSUMER_CONFIG });
13
        context = new ClassPathXmlApplicationContext(new String[] { DubboServiceProviderStart.DUBBO_CONSUMER_CONFIG });
13
        context.start();
14
        context.start();
14
    }
15
    }
15
    
16
    
16
17
17
    public void testHello() {
18
    public void testHello() {
18
        // TODO Auto-generated method stub
19
        HelloService helloService = (HelloService)context.getBean("helloService"); // 获取远程服务代理
19
        HelloService helloService = (HelloService)context.getBean("helloService"); // 获取远程服务代理
20
        String result = helloService.hello("测试名称"); // 执行远程方法
20
        String result = helloService.hello("测试名称"); // 执行远程方法
21
        System.out.println(result); // 显示调用结果
21
        System.out.println(result); // 显示调用结果
22
    }
22
    }
23
    
24
    public void testIHello() {
25
        IHelloService helloService = (IHelloService)context.getBean("iHelloService"); // 获取远程服务代理
26
        String result = helloService.hello("测试名称"); // 执行远程方法
27
        System.out.println(result); // 显示调用结果
28
    }
23
}
29
}