正在加载图片...
public static void set Context(org. springframework context Application Context context) Application Context context=context *取得在上下文配置文件中定义的类的实例。p> 当<code>name</code>为nuI或者长度为0的字符串时,抛出<code> IllegalArgumentException</code>异常 param name在上下文配置文件中定义的类的名称 <code>name<code>为nul或者<code>name</code>对应的对象不存在时, 抛出< code>java. lang. IllegalAccessException<code>异常,并记录 error日志 areturn Object类的实例 if(name=null name length(==0)i throw new Illegal Argument Exception("必须指定要创建的对象的name"), Object ret=null context. get Bean( name) 1 catch(NoSuch Bean Definition Exception nsbde)i log errort("找不到指定的对象[name="+name+"]", nsbde) i catch( Beans Exception be)t log error("无法创建指定的对象[name="+name+"]",be), } return ret: 在 Struts中的 action中调用 Spring的事务管理 public Action Forward execute( final Action Mapping mapping, final Action Form form, final hTtp Servletrequest request final Http servlet Response response)throws Exception i*/ public static void setContext(org.springframework.context.ApplicationContext context) { ApplicationContext.context = context; } /** * 取得在上下文配置文件中定义的类的实例。<p> * 当<code>name</code>为 null 或者长度为 0 的字符串时,抛出<code>IllegalArgumentException</code>异常。 * @param name 在上下文配置文件中定义的类的名称。 * <code>name</code> 为 null 或者 <code>name</code> 对应的对象不存在时, * 抛出 <code>java.lang.IllegalAccessException</code> 异常,并记录 error 日志 * @return Object 类的实例 */ public static Object getBean(String name) { if (name == null || name.length() == 0) { throw new IllegalArgumentException("必须指定要创建的对象的 name"); } Object ret = null; try { ret = context.getBean(name); } catch (NoSuchBeanDefinitionException nsbde) { log.error("找不到指定的对象 [name=" + name + "]", nsbde); } catch (BeansException be) { log.error("无法创建指定的对象 [name=" + name + "]", be); } return ret; } } 在 Struts 中的 action 中调用 Spring 的事务管理 public ActionForward execute(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有