首页 > 其他 > 详细

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

时间:2019-07-07 01:04:32      阅读:147      评论:0      收藏:0      [点我收藏+]

 

 

在消费者消费的时候,无论怎么样 都无法 找到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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!