加载spring配置文件的工具类
2007-07-13 14:59
471 查看
public class AppContext {
private static AppContext instance;
private AbstractApplicationContext appContext;
public synchronized static AppContext getInstance() {
if (instance == null) {
instance = new AppContext();
}
return instance;
}
private AppContext() {
this.appContext = new ClassPathXmlApplicationContext(
"applicationContext.xml");
}
public AbstractApplicationContext getAppContext() {
return appContext;
}
}
在BaseAction中
public class BaseAction extends Action ...{
public BaseAction() ...{
super();
}
protected IBookService getBookService() ...{
return (IBookService) AppContext.getInstance().getAppContext(). getBean(
"bookService");
}
protected IOrderService getOrderService() ...{
return (IOrderService) AppContext.getInstance().getAppContext(). getBean(
"orderService");
}
protected ICustomerService getCustomerService() ...{
return (ICustomerService) AppContext.getInstance().getAppContext(). getBean(
"customerService");
}
protected IOrderItemService getOrderItemService() ...{
return (IOrderItemService) AppContext.getInstance().getAppContext(). getBean(
"orderItemService");
}
protected String checkUser(HttpServletRequest request,
HttpServletResponse response)...{
Customer user = null;
user = (Customer) request.getSession().getAttribute("user");
if(user==null)...{
System.out.println("you have no loginning!!!!");
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_MESSAGE,new ActionError("errors. login"));
this.saveErrors(request,errors);
return null;
}else...{
return user.getCustName();
}
}
}
private static AppContext instance;
private AbstractApplicationContext appContext;
public synchronized static AppContext getInstance() {
if (instance == null) {
instance = new AppContext();
}
return instance;
}
private AppContext() {
this.appContext = new ClassPathXmlApplicationContext(
"applicationContext.xml");
}
public AbstractApplicationContext getAppContext() {
return appContext;
}
}
在BaseAction中
public class BaseAction extends Action ...{
public BaseAction() ...{
super();
}
protected IBookService getBookService() ...{
return (IBookService) AppContext.getInstance().getAppContext(). getBean(
"bookService");
}
protected IOrderService getOrderService() ...{
return (IOrderService) AppContext.getInstance().getAppContext(). getBean(
"orderService");
}
protected ICustomerService getCustomerService() ...{
return (ICustomerService) AppContext.getInstance().getAppContext(). getBean(
"customerService");
}
protected IOrderItemService getOrderItemService() ...{
return (IOrderItemService) AppContext.getInstance().getAppContext(). getBean(
"orderItemService");
}
protected String checkUser(HttpServletRequest request,
HttpServletResponse response)...{
Customer user = null;
user = (Customer) request.getSession().getAttribute("user");
if(user==null)...{
System.out.println("you have no loginning!!!!");
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_MESSAGE,new ActionError("errors. login"));
this.saveErrors(request,errors);
return null;
}else...{
return user.getCustName();
}
}
}
相关文章推荐
- Spring-配置文件加载工具
- SqlMapConfig.xml --- 在spring配置文件中自动加载的mybatis文件
- junit进行测试加载多个spring配置文件
- 详解Spring Boot加载properties和yml配置文件
- spring 中加载xml配置文件的方式
- 快速上手Spring--3. 加载Bean的配置文件
- Spring之配置文件加载方式
- 请慎用spring-ClassPathXmlApplicationContext手动加载spring配置文件
- spring配置文件的加载
- SpringMVC加载自定义目录下的springmvc.xml配置文件
- java加载spring配置文件
- spring的配置文件和加载
- Spring源码分析:Bean加载流程概览及配置文件读取
- Spring加载properties配置资源文件的应用
- Spring配置文件加载时出现Bean property 'newscontentDAO' is not writable or has an invalid setter method错误的解决[00原创]
- Spring+mybatis+maven整合过程加载配置文件jdbc.properties
- 加载自定义目录下的springmvc.xml配置文件 (2)
- 加载spring配置文件的常用三种方法
- Spring加载配置文件的3种方法
- Spring加载多个配置文件