java普通类如何调用Spring的Service层?

首先在Service层上面添加 @Service("myService")

然后,在main方法中调用,String[]中为配置文件,如下所示:

 ApplicationContext applicationContext=new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml","spring-mvc.xml","spring-mybatis.xml"});
 MyService myService=(MyService)applicationContext.getBean("myService");

猜你喜欢

转载自www.cnblogs.com/expiator/p/9169272.html