Spring Boot整合Dubbo

This commit is contained in:
zhaiyongchao
2016-07-14 10:54:13 +08:00
parent 47032cd6b7
commit 7f0bfb5afe
16 changed files with 283 additions and 72 deletions
@@ -0,0 +1,20 @@
package com.didispace;
import org.apache.log4j.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;
import java.util.concurrent.CountDownLatch;
@SpringBootApplication
@ImportResource({"classpath:dubbo.xml"})
public class Application {
public static void main(String[] args) throws InterruptedException {
SpringApplication.run(Application.class, args);
}
}
@@ -0,0 +1,10 @@
package com.didispace.service;
/**
* Created by zhaiyc on 2016/7/14.
*/
public interface ComputeService {
Integer add(int a, int b);
}
@@ -0,0 +1,24 @@
package com.didispace.web;
import com.didispace.service.ComputeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by zhaiyc on 2016/7/14.
*/
@RestController
public class ComputeController {
@Autowired
private ComputeService computeService;
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String add(@RequestParam Integer a, @RequestParam Integer b) {
return String.valueOf(a + b);
}
}
@@ -0,0 +1,5 @@
#ZooKeeper
dubbo.registry.address=localhost:2181
logging.level.root=DEBUG
@@ -0,0 +1,18 @@
<?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:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!-- 消费方应用名 -->
<dubbo:application name="consumer" />
<!-- 注册中心服务地址 -->
<dubbo:registry id="zookeeper" protocol="zookeeper" address="${dubbo.registry.address}" />
<!-- 引用ComputeService服务-->
<dubbo:reference id="computeService" interface="com.didispace.service.ComputeService"
check="false" version="1.0" url="" registry="zookeeper" protocol="dubbo" timeout="15000"/>
</beans>
@@ -0,0 +1,24 @@
package com.didispace;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
public class ApplicationTests {
@Before
public void setUp() throws Exception {
}
@Test
public void getHello() throws Exception {
}
}