
五.springboot集成dubbo(无admin)
-
先搭建两个微服务工程provider/consumer
1.pom.xml
org.springframework.boot
spring-boot-starter-parent
2.0.4.RELEASE
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-devtools
test
org.springframework.boot
spring-boot-maven-plugin
2.application.properties--provider
spring.application.name
=
dubbo-spring-boot-provider/consumer
2.application.properties--consumer
spring.application.name
=
dubbo-spring-boot-consumer
server.port
=
8084
3。创建
启动类ProviderApplication/ConsumerApplication
@SpringBootApplication
public class ProviderApplication{
public static void main(String[] args) {
SpringApplication.
run(ProviderApplication.class, args);
}
}
4.创建访问
接口
@Controller
@RequestMapping
public class HelloController {
@RequestMapping("/getHello")
@ResponseBody
public String getHello(){
return "hello my springboot";
}
}
5.分别main方法启动启动类
1.引入dubbo依赖
com.alibaba.spring.boot
dubbo-spring-boot-starter
2.0.0
2.启动类
添加注解
@EnableDubboConfiguration
3.application.properties
spring.dubbo.registry=N/A
spring.dubbo.server=true
4.添加业务处理接口
public interface DubboService {
public String getName(String name);
}
import com.alibaba.dubbo.config.annotation.Service;
import com.example.service.DubboService;
import org.springframework.stereotype.Component;
@Component //spring的bean配置
@Service(interfaceClass = DubboService.class) //相当于dubbo:service interface暴露配置
public class DubboServiceImpl implements DubboService{
@Override
public String getName(String name) {
return "姓名:"+name;
}
}
5.main方法启动启动类
1.引入dubbo依赖
com.alibaba.spring.boot
dubbo-spring-boot-starter
2.0.0
2.启动类添加注解
@EnableDubboConfiguration
3.添加业务处理接口
public interface DubboService {
public String getName(String name);
}
4.修改consumer访问接口
import com.alibaba.dubbo.config.annotation.Reference;
import com.example.service.DubboService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping
public class TestController {
@Reference(url = "dubbo://localhost:20880")
DubboService dubboService;
@ResponseBody
@RequestMapping(value = "/abc",method = RequestMethod.
GET)
public String abc(String name){
// return "nihao";
return dubboService.getName(name);
}
}
5.main方法启动启动类
访问
http://localhost:8084/abc?name=ninds
评论列表(0条)