dubbo 回声测试,Spring + new Applicat

2017-09-04  本文已影响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);

}

}


异常贴图:

上一篇 下一篇

猜你喜欢

热点阅读