美文网首页
dubbo 回声测试,Spring + new Applicat

dubbo 回声测试,Spring + new Applicat

作者: 藤原咸鱼 | 来源:发表于2017-09-04 17:56 被阅读0次

仿照官网一段代码,网上也都是这么写的,在Spring项目中会有问题

public static voidmain(String[] a) {

ClassPathXmlApplicationContext context =newClassPathXmlApplicationContext("spring/spring.xml");

EchoService echoService = (EchoService) context.getBean("errorService");

String echo = (String) echoService.$echo("ok");

System.out.println("===Scheduled===="+ echo);

}


lassPathXmlApplicationContext context =newClassPathXmlApplicationContext("spring/spring.xml"); 类

会与Spring启动类 @@ImportResource({"classpath*:spring/spring.xml"}) 重复加载导致Duplicate spring bean id

正确示例:

@Component

public classEchoSound {

@Autowired

private ApplicationContextcontext;

@Scheduled(fixedRate =1000)

public voidmain() {

EchoService echoService = (EchoService)context.getBean("errorService");

String echo = (String) echoService.$echo("ok");

System.out.println("===Scheduled===="+ echo);

}

}


异常贴图:

相关文章

网友评论

      本文标题:dubbo 回声测试,Spring + new Applicat

      本文链接:https://www.haomeiwen.com/subject/vgwejxtx.html