//手动加载spring配置文件
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[]{"/spring/spring-mvc.xml","/spring/spring-redis.xml","/spring/spring-mybatis.xml","/spring/spring-main.xml"});
//获取bean,getBean("commandService")中的commandService指的是@Service("commandService")
CommandMapper commandService = (CommandMapper) applicationContext.getBean("commandService");
@Service("commandService")
public class CommandServiceImpl implements CommandMapper{
... ...
}
1.加载多个配置文件
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[]{"/spring/spring-mvc.xml","/spring/spring-redis.xml","/spring/spring-mybatis.xml","/spring/spring-main.xml"});
2.获取bean方式
@Service("commandService")
public class CommandServiceImpl implements CommandMapper{
... ...
}
CommandMapper a=(CommandMapper) applicationContext.getBean("commandService");