总结下今天学习遇到的问题

 

 

在消费者消费的时候,无论怎么样 都无法 找到mapping:

代码的目录结构是这样的:

总共两个工程。一个是ticket属于生产者,里面的service就打印一句话:get a ticket   然后消费者 user工程。测试类调用

package com.liqs.consolver.people;

import com.liqs.consolver.people.service.GetTicketService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@RunWith(SpringRunner.class)
@SpringBootTest
public class PeopleApplicationTests {

    @Autowired
    GetTicketService getTicketService;

    @Test
    public void getTicket() {
        System.out.println( getTicketService.getUserTicket());//调用tichetService打印
    }

}

  注意的是,这里的 文件目录有一个 和ticket一样的结构的ticket接口

  

 

 service代码:

package com.liqs.consolver.people.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.liqs.consolver.people.service.GetTicketService;
import com.liqs.producter.ticket.service.TicketService;
import org.springframework.stereotype.Service;

@Service
public class GetTicketServiceImpl implements GetTicketService {
    @Reference
    TicketService ticketService;
    @Override
    public String getUserTicket() {
        return ticketService.getTicket();
    }
}

  

 测试类代码:

package com.liqs.consolver.people;

import com.liqs.consolver.people.service.GetTicketService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@RunWith(SpringRunner.class)
@SpringBootTest
public class PeopleApplicationTests {

    @Autowired
    GetTicketService getTicketService;

    @Test
    public void getTicket() {
        System.out.println( getTicketService.getUserTicket());
    }

}

  调用后,控制台报错

 

后来偶然发现,原来enablexxx注解里有@EnableDubbo这个属性,把它加上就好了

然后修改后的代码tiket代码 如下

package com.liqs.producter.ticket;

import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableDubbo//加入这个注解才有用
public class TicketApplication {

    public static void main(String[] args) {
        SpringApplication.run(TicketApplication.class, args);
    }

}

 

转载于:https://www.cnblogs.com/liqs-note/p/11144373.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值