当我执行下面的代码时,我正在获取属性“sql”是必需的错误。有人能帮我吗?我不知道如何在TestDAO calss中注入Datasource以使其正常工作。
public class TestDAO extends BaseStoredProcedure
{
final protected Logger logger = Logger.getLogger(this.getClass().getName());
private static final String SPROC_NAME = "dbo.SP1";
@Autowired
private JdbcTemplate jdbcTemplate;
public java.util.ArrayList<IssuerProductResponse> validIssuersProducts(java.util.ArrayList<IssuerProductRequest> issuersProducts)
{
//PARAM MAP set here
//compile SP
HIOSBaseStoredProcedure hiosBaseSP = new HIOSBaseStoredProcedure(jdbcTemplate.getDataSource(),SPROC_NAME,inMap,null,null,null);
//now set parameters
Map<String, Object> result = super.execute(parameters);
System.out.println(result);
return liReponse;
}
}
BaseStoreProcedure类
public class BaseStoredProcedure extends StoredProcedure {
public BaseStoredProcedure() {
super();
// TODO Auto-generated constructor stub
}
/**
*
* @param ds
* @param spname
* @param map
* @param sqlOutKey
* @param returnType
* @param rowmapper
*/
public BaseStoredProcedure (DataSource ds, String spname,
Map<String, Integer> map, String sqlOutKey, Integer returnType,
RowMapper rowmapper) {
super();
setDataSource(ds);
/* resultset has to be declared first over other declare parameters */
if (rowmapper != null) {
declareParameter(new SqlReturnResultSet(sqlOutKey, rowmapper));
}
if (map != null) {
Iterator itr = map.keySet().iterator();
while (itr.hasNext()) {
String key = (String) itr.next();
Integer value = (Integer) map.get(key);
declareParameter(new SqlParameter(key, value.intValue()));
}
}
/*
* sql out paramter has to be declared based on the order in stored
* procedures, In all our stored procedures we have it after input
* parameters
*/
if (returnType != null) {
declareParameter(new SqlOutParameter(sqlOutKey, returnType
.intValue()));
}
setSql(spname);
compile();
}
}
Spring配置
<bean id="dao" class="test.dao.TestDAO"> <property name="jdbcTemplate" ref="jdbcTemplate"></property> </bean>
<bean id="baseSP" class="test.dao.BaseStoredProcedure"> </bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" /> <property name="url" value="jdbc:sqlserver://IP:1433;databaseName=DB;" /> <property name="username" value="username" /> <property name="password" value="password" /> <property name="validationQuery" value="SELECT 1" /> <property name="initialSize" value="1"/> <property name="maxActive" value="20"/> </bean>