在weblogic 10.3.6服务器中,我已经定义了as400数据源,现在我使用myEclipse和java spring框架来开发程序,通过使用namedParameterjdbctemplate来访问as400 db。我有as400 select语句的sql。我在我的项目中的applicationContext.xml中定义了xml代码。有没有办法使用jdbcParameterNamedTemplate来运行,因为我知道jdbcTemplate需要有数据源,它将具有连接字符串或密码,我不想在代码中输入这些值,但仍然使用weblogic数据源?有没有例子??
<beans>
<bean id="AS400UATJdbcTemplate" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="AS400UAT"/>
<property name="lookupOnStartup" value="false"/>
<property name="cache" value="true"/>
<property name="proxyInterface" value="javax.sql.DataSource"/>
</bean>
<bean id="getCreditCardByAccountsNumeStoredProcedure" class="com.as400function.GetAccountsByTypeStoredProcedure" singleton="false">
<constructor-arg>
<ref bean="AS400UATJdbcTemplate"/>
</constructor-arg>
</bean>
<bean id="AddSingleWithCreditCard" class="com.as400function.AddSingleWithCreditCard" singleton="false">
<constructor-arg>
<ref bean="AS400UATJdbcTemplate"/>
</constructor-arg>
</bean>
</beans>
答案 0 :(得分:0)
我修改了applicationContext.xml
<bean id="AS400ForOct" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="AS400UAT"/>
</bean>
<bean id="getCreditCardByAccountsNumeStoredProcedure" class="com.aeon.awip.membersite.as400function.GetCreditCardByAccountsNumeStoredProcedure" singleton="false">
<property name="dataSource">
<ref bean="AS400ForOct" />
</property>
</bean>
修改了构造函数的Class文件:
public class GetCreditCardByAccountsNumeStoredProcedure extends JdbcDaoSupport{
public GetOctopusCreditCardByAccountsNumeStoredProcedure (DataSource datasource){
setDataSource(datasource);
}
public GetOctopusCreditCardByAccountsNumeStoredProcedure() {
super();
}
.......
}
添加以下代码以致电
ApplicationContext ctx = ServiceLocator.getApplicationContext();
getCreditCardByAccountsNumeStoredProcedure = (GetCreditCardByAccountsNumeStoredProcedure)ctx.getBean("getCreditCardByAccountsNumeStoredProcedure");