📄 servicelocatorbean.java
字号:
package login.view.bean;
import javax.servlet.ServletContext;
import login.model.service.UserService;
import login.view.servicelocator.ServiceLocator;
import login.view.util.FacesUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
public class ServiceLocatorBean implements ServiceLocator {
// the logger for this class
private static final Log log = LogFactory.getLog(ServiceLocatorBean.class);
// the user service bean name
private static final String USER_SERVICE_BEAN_NAME = "userService";
// the Spring application context
private ApplicationContext appContext;
// the cached user service
private UserService userService;
public ServiceLocatorBean() {
ServletContext context = FacesUtils.getServletContext();
this.appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
this.userService = (UserService) this
.lookupService(USER_SERVICE_BEAN_NAME);
this.log.info("Service locator bean is initialized");
}
public UserService getUserService() {
return this.userService;
}
public Object lookupService(String serviceBeanName) {
return appContext.getBean(serviceBeanName);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -