其他分享
首页 > 其他分享> > Spring工程搭建

Spring工程搭建

作者:互联网

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 {

}
}
}

标签:String,工程,beanFactory,Spring,BeansException,void,UserService,public,搭建
来源: https://www.cnblogs.com/IUaena/p/14588332.html