程序代碼: |
public class BaseAction extends DispatchAction { ... public Object getBean(String name) { if (ctx == null) { ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(servlet.getServletContext()); } return ctx.getBean(name); } } |
程序代碼: |
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"> <set-property property="contextConfigLocation" value="/WEB-INF/action-servlet.xml" /> </plug-in> |
程序代碼: |
<bean id="userService" class="com.nic.service.UserServiceImpl"> <property name="userDao"> <ref bean="userDao" /> </property> </bean> <bean name="/userAction" class="com.stamen.web.UserAction"> <property name="userService" ref="userService"/> </bean> |
程序代碼: |
public class ServiceLocator private static ApplicationContext factory = null; public static void init(ApplicationContext ctx) { factory = ctx; } public static LogService getLogService() { return (LogService) ServiceLocator.getBean("logService"); } public static UserService getUserService() { return (UserService) ServiceLocator.getBean("userService"); } public static PieeService getPieeService() { return (PieeService) ServiceLocator.getBean("pieeService"); } public static PieeGrid getPieeListService() { return (PieeGrid) ServiceLocator.getBean("pieeListService"); } ... } |