1.首先idea新建一个springboot项目,这里简单介绍下:
2.在springboot启动类上加入注解
@ImportResource(locations = {"classpath*:dubbo_config/*.xml"})
locations 为你的dubbo相关配置文件路径
3.pom文件配置
<?xml version="1.0" encoding="UTF-8"?>4.0.0org.springframework.boot spring-boot-starter-parent 2.1.9.RELEASEcom.example demo 0.0.1-SNAPSHOTdemoDemo project for Spring Boot1.8org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test testcom.** ****-api 1.2.4com.** ****-client 1.2.4io.dubbo.springboot spring-boot-starter-dubbo RELEASEorg.apache.zookeeper zookeeper 3.4.6org.slf4j slf4j-log4j12 log4j log4j org.springframework.boot spring-boot-maven-plugin
4.application name配置
<?xml version="1.0" encoding="UTF-8"?>
5.controller调用
@Controllerpublic class MemberIndexController { @Autowired private DemoService demoService; /** * @RestController 相当于@Controller + @ResponseBody * 第一种启动方式:@EnableAutoConfiguration 注解作用:扫描范围:默认当前类里面, * SpringApplication.run(MemberController.class); * 第二种加上扫描范围 */ @RequestMapping("/memberIndex") @ResponseBody public String memberIndex() { demoService.sayHello("SpringBoot Dubbo test"); System.out.println("memberIndex"); return "springboot成功+memberIndex"; }}