1

全部。随函附上所有文件。如果我为 bean 属性name和赋予相同的名称reference,它会返回对象。但它返回 null,以防两者不同。请帮忙。太感谢了。

AuthenticateAction.java文件里面有详细的注释......

以下是我的文件列表:

WIRAdminBaseAction.java ---> my base action 
AuthenticateAction.java ---> my java file that calls the bean here 
applicationContext_MNC.xml 

下面的调用方式......不鼓励这样做,因为我们不应该总是使用 applicationContext

ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(getServletRequest().getSession().getServletConte xt()); 
ICacheDelegate cacheAction = (ICacheDelegate)applicationContext.getBean("BMOCacheDelegate"); 

下面的调用方式不起作用......返回空值......请帮助......我假设,因为我已经扩展了 WIRAdminBaseAction,我应该能够直接调用 getCacheDelegate 并且它应该返回我的 cacheDelegate对象...再次,请注意.....如果我将 applicationContext_MNC.xml 更改如下,则以下调用方式可以正常工作。但是,由于某些必要性,我不想如下更改我的 applicationContext_MNC.xml。

<bean id="BMOWIRAdminBaseAction" class="com.symcor.wiradmin.web.action.WIRAdminBase Action"> 
<property name="cacheDelegate"> 
<ref bean="cacheDelegate" /> 
</property> 
</bean> 

<bean id="cacheDelegate" class="com.symcor.wiradmin.delegate.CacheDelegate" > 
<property name="statusDBDAO"><ref bean="BMOStatusDBDAO" /></property> 
</bean> 

是不是名称和bean应该具有相同的值....???不需要……我说得对吗?请指教。

getCacheDelegate().getActorAction(1); // this way of calling doesn't work and returns null value. please help. 

我的代码如下。


AuthenticateAction.java 

package com.symcor.wiradmin.web.action; 

import java.net.UnknownHostException; 
import java.sql.SQLException; 

import org.bouncycastle.crypto.CryptoException; 
import org.springframework.context.ApplicationContext; 
import org.springframework.dao.DataAccessException; 
import org.springframework.web.context.support.WebApplica tionContextUtils; 

import com.symcor.wiradmin.delegate.ICacheDelegate; 

public class AuthenticateAction extends WIRAdminBaseAction { 

private static final long serialVersionUID = 1L; 

public String authenticate() throws UnknownHostException, CryptoException, 
DataAccessException, SQLException{ 

/** This way of calling works...... This is not encouraged, as we should not use applicationContext always **/ 
ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContex t(getServletRequest().getSession().getServletConte xt()); 
ICacheDelegate cacheAction = (ICacheDelegate) applicationContext.getBean("BMOCacheDelegate"); 

/** The below way of calling does NOT work .... returns null value.... Please help... 
* I assume that, since I have extended the WIRAdminBaseAction, i should be able to call the getCacheDelegate directly 
* and it should return my cacheDelegate object ... 
* Again, Please note.....if I change my applicationContext_MNC.xml as below, the below way of calling works fine... 
* but, i don't want to change my applicationContext_MNC.xml as below, due to some necessity. 

<bean id="BMOWIRAdminBaseAction" class="com.symcor.wiradmin.web.action.WIRAdminBase Action"> 
<property name="cacheDelegate"> 
<ref bean="cacheDelegate" /> 
</property> 
</bean> 

<bean id="cacheDelegate" class="com.symcor.wiradmin.delegate.CacheDelegate" > 
<property name="statusDBDAO"><ref bean="BMOStatusDBDAO" /></property> 
</bean> 

... is it that the name and bean should have the same value.... ??? No Need to be.....Am i right ? Please advise. 
* 
* **/ 


getCacheDelegate().getActorAction(1); // this way of calling doesn't work and returns null value. please help. 

return "success"; 
} 
} 


WIRAdminBaseAction.java 

package com.symcor.wiradmin.web.action; 


import java.util.Map; 

import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 

import org.apache.struts2.interceptor.ParameterAware; 
import org.apache.struts2.interceptor.SessionAware; 

import com.opensymphony.xwork2.ActionSupport; 
import com.opensymphony.xwork2.Preparable; 
import com.opensymphony.xwork2.config.entities.Parameteri zable; 
import com.symcor.wiradmin.delegate.ICacheDelegate; 

public class WIRAdminBaseAction extends ActionSupport implements Preparable, ParameterAware, Parameterizable, SessionAware,RequestAware { 

private HttpServletRequest request; 
private static final long serialVersionUID = 1L; 
private HttpServletResponse response; 

private ICacheDelegate cacheDelegate; 

private Map session; 

private Map<String, String> params; 

private Map parameters; 

public void prepare() throws Exception { 
} 

public String execute() throws Exception { 
return SUCCESS; 
} 

public void setServletRequest(HttpServletRequest request) { 

this.request = request; 
} 

public HttpServletRequest getServletRequest() { 
return this.request; 
} 

public void setServletResponse(HttpServletResponse response) { 
this.response = response; 
} 

public HttpServletResponse getServletResponse() { 
return this.response; 
} 

public ICacheDelegate getCacheDelegate() { 
return cacheDelegate; 
} 

public void setCacheDelegate(ICacheDelegate cacheDelegate) { 
this.cacheDelegate = cacheDelegate; 
} 

public void addParam(final String key, final String value) { 
this.params.put(key, value); 
} 

public Map getParams() { 
return params; 
} 

public void setParams(final Map<String, String> params) { 
this.params = params; 
} 

public Map getSession() { 
return this.session; 
} 

public void setSession(final Map session) { 
this.session = session; 
} 

public void setParameters(final Map param) { 
this.parameters = param; 
} 

} 


applicationContext_MNC.xml 

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
"http://www.springframework.org/dtd/spring-beans.dtd"> 

<beans> 

<!-- database configuration from property file --> 
<bean id="BMOAdminDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" 
destroy-method="close" lazy-init="default" autowire="default" dependency-check="default"> 
<property name="driverClass" value="${jdbc.driver}" ></property> 
<property name="jdbcUrl" value="${admin.jdbc.url}" ></property> 
<property name="user" value="${admin.jdbc.user}" ></property> 
<property name="password" value="${admin.jdbc.password}" ></property> 
<property name="initialPoolSize" value="3" ></property> 
<property name="minPoolSize" value="3" ></property> 
<property name="maxPoolSize" value="25" ></property> 
<property name="acquireIncrement" value="1" ></property> 
<property name="acquireRetryDelay" value="1000" ></property> 
<property name="debugUnreturnedConnectionStackTraces" value="true" ></property> 
<property name="maxIdleTime" value="300" ></property> 
<property name="unreturnedConnectionTimeout" value="300000" ></property> 
<property name="preferredTestQuery" value="SELECT COUNT(*) FROM LOCALE_CODE" ></property> 
<property name="checkoutTimeout" value="300000" ></property> 
<property name="idleConnectionTestPeriod" value="600000" ></property> 
</bean> 

<bean id="BMOWIRAdminBaseAction" class="com.symcor.wiradmin.web.action.WIRAdminBase Action"> 
<property name="cacheDelegate"> 
<ref bean="BMOCacheDelegate" /> 
</property> 
</bean> 

<bean id="BMOCacheDelegate" class="com.symcor.wiradmin.delegate.CacheDelegate" > 
<property name="statusDBDAO"><ref bean="BMOStatusDBDAO" /></property> 
</bean> 

<bean id="BMOStatusDBDAO" class="com.symcor.wiradmin.dao.StatusDBDAO"> 
<property name="dataSource"> 
<ref bean="BMOAdminDataSource" /> 
</property> 
</bean> 

<!-- this bean is set to map the constants which needs to be configured as per 
the environment to the java constants file --> 
<bean id="envConstantsConfigbean" class="com.symcor.wiradmin.util.constants.Environm entConstantsSetter"> 
<property name="loginUrl" value="${login.url}"/> 
<property name="logoutIR" value="${logout.from.image.retrieval}"/> 
<property name="adminModuleUrl" value="${admin.url}"/> 
<property name="adminUrlSym" value="${admin.url.sym}"/> 
<property name="envProperty" value="${env.property}"/> 
</bean> 

</beans> 
4

0 回答 0