java代碼: |
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> |
java代碼: |
<interceptor name="autowire" class="com.opensymphony.xwork.spring.interceptor.ActionAutowiringInterceptor"> <param name="autowireStrategy"> @org.springframework.beans.factory.config.AutowireCapableBeanFactory@AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE </param> </interceptor> |
java代碼: |
protected void before(ActionInvocation invocation) throws Exception { if (!initialized) { ApplicationContext applicationContext = (ApplicationContext)ActionContext.getContext().getApplication().get( WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (applicationContext == null) { log.warn("ApplicationContext could not be found. Action classes will not be autowired."); } else { setApplicationContext(applicationContext); factory = new SpringObjectFactory(); factory.setApplicationContext(getApplicationContext()); if (autowireStrategy != null) { factory.setAutowireStrategy(autowireStrategy.intValue()); } } initialized = true; } if (factory == null) return; Action bean = invocation.getAction(); factory.autoWireBean(bean); ActionContext.getContext().put(APPLICATION_CONTEXT, context); } |