servicelocatorbean.java

来自「spring+Hibernate +jsf」· Java 代码 · 共 44 行

JAVA
44
字号
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 + =
减小字号Ctrl + -
显示快捷键?