public ClassPathXmlApplicationContext(String configLocation) throws BeansException {
this(new String[] {configLocation}, true, null);
}
package services;
public interface UserService {
public void saveUser();
}
---------------------
package services.impl;
import services.UserService;
public class UserServiceImpl implements UserService {
public void saveUser() {
System.out.println("service的save方法执行了");
}
}
----------------------
public class DemoTest {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
UserService service = (UserService) context.getBean("userService");
service.saveUser();
}
}
--------------------
public ClassPathXmlApplicationContext(
String[] configLocations,
boolean refresh,
@Nullable ApplicationContext parent)
throws BeansException {
super(parent);
setConfigLocations(configLocations);
if (refresh) {
refresh();
}
}
--------------------------
public void refresh() throws BeansException, IllegalStateException {
synchronized (this.startupShutdownMonitor) {
prepareRefresh();
ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();
prepareBeanFactory(beanFactory);
try {
postProcessBeanFactory(beanFactory);
finishBeanFactoryInitialization(beanFactory);
finishRefresh();
} catch (BeansException ex) {
} finally {
}
}
}