spring boot 集成 rabbitmq
1、使用默认的AmqpTemplate生产消费pojo时,pojo需要implement Serializable,否则会抛出org.springframework.amqp.AmqpException: No method found for class [B。
2、当需要使用其他package或者其他module的@Component时,可以在SpringApplication类的注解加入@ComponentScan("com.xxxx.xxx");
3、spring boot主动执行的方法可以通过
@Component public class SenderApp implements ApplicationRunner{ @Autowired private Sender sender; @Override public void run(ApplicationArguments args) throws Exception { OrderEntrust orderEntrust = JSON.parseObject("{\n" + " \"id\":1,\n" + " \"orderdate\":20180706,\n" + " \"fundid\":1,\n" + " \"assetid\":4,\n" + " \"combiid\":6,\n" + " \"operatorno\":1,\n" + " \"marketclassify\":\"上交所\",\n" + " \"securityinternalcode\":\"601318\",\n" + " \"buysell\":\"买\",\n" + " \"openclose\":\"\",\n" + " \"orderprop\":\"限价指令\",\n" + " \"entrustprice\":56.94,\n" + " \"entrustvolume\":200\n" + "}".trim(), OrderEntrust.class); sender.sendOrderEntrust(orderEntrust); }
这种方式载入。