Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何迁移Java、Spring项目以使用JNDI数据源_Java_Spring_Jdbc_Jboss_Jndi - Fatal编程技术网

如何迁移Java、Spring项目以使用JNDI数据源

如何迁移Java、Spring项目以使用JNDI数据源,java,spring,jdbc,jboss,jndi,Java,Spring,Jdbc,Jboss,Jndi,我有一个从命令行运行的Java项目。它使用的是弹簧。目前我的项目是mySQL。使用可以从下面的config.xml中看到 <bean id="mysqldataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <

我有一个从命令行运行的Java项目。它使用的是弹簧。目前我的项目是mySQL。使用可以从下面的config.xml中看到

<bean id="mysqldataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="mysqldataSource.url" />
    <property name="username" value="mysqldataSource.username" />
    <property name="password" value="mysqldataSource.password" />
</bean>

我的公司要求我将项目从使用MySQL改为使用JNDI数据源

下面是我的java代码,您可以看到它使用的是jdbcTemplate:

public class DisasterReliefMySQLImpl extends JdbcTemplate implements
        DisasterReliefMySQL {

    private static Log log = LogFactory.getLog(DisasterReliefMySQLImpl.class
            .getName());

    String querySQL;
    int counter = 0;

    public int getCounter() {
        return counter;
    }

    private String getQuerySQL() {
        return querySQL;
    }

    private void setQuerySQL(String querySQL) {
        this.querySQL = querySQL;
    }

    DisasterReliefMySQLImpl(DataSource ds) {
        super(ds);
    }


    DisasterReliefMySQLImpl(DataSource ds, String querySQL) {
        super(ds);
        setQuerySQL(querySQL);
    }

    public int updateDonation(String id) {
        Long eTime = System.currentTimeMillis() / 1000;

        String updateSQL = "update uft_donation set sent_to_mbs="
                + eTime.toString() + " where  donation_id =" + id;

        return (int) this.update(updateSQL);
    }

    public List<Donation> returnResults() {
        log.debug("Starting returnResults...");

        List<Donation> Donations = new ArrayList<Donation>();

        List<Map<String, Object>> rows = this.queryForList(getQuerySQL());

        counter = 0;

        for (Map row : rows) {
            Donation d = new Donation();

            d.setDonationID((Long) row.get("donation_id"));
            d.setCCTransactionNumber((String) row.get("txn_id"));
            d.setProgramCode((String) row.get("gl_code"));
            d.setLastName((String) row.get("billing_last_name"));
            d.setFirstName((String) row.get("billing_first_name"));
            d.setAmount((String) row.get("mc_gross"));
            d.setAddressLine1((String) row.get("billing_street1"));
            d.setAddressLine2((String) row.get("billing_street2"));
            d.setCity((String) row.get("billing_city"));
            d.setState((String) row.get("zone_code"));
            d.setZipCode((String) row.get("billing_postal_code"));
            d.setCountry((String) row.get("country_name"));

            Donations.add(d);
            counter++;
        }

        log.debug(counter + " Donation(s) loaded");
        return Donations;
    }

}
公共类DisasterReliefMySQLImpl扩展JdbcTemplate实现
灾难救济{
私有静态日志Log=LogFactory.getLog(DisasterReliefMySQLImpl.class
.getName());
字符串查询SQL;
int计数器=0;
公共int getCounter(){
返回计数器;
}
私有字符串getQuerySQL(){
返回querySQL;
}
私有void setQuerySQL(字符串querySQL){
this.querySQL=querySQL;
}
DisasterReliefMySqImpl(数据源ds){
超级(ds),;
}
DisasterReliefMySQLLIML(数据源ds,字符串querySQL){
超级(ds),;
setQuerySQL(querySQL);
}
public int updateNation(字符串id){
Long-eTime=System.currentTimeMillis()/1000;
String updateSQL=“更新uft\U捐赠集已发送到\U mbs=”
+eTime.toString()+“其中捐赠_id=“+id;
返回(int)this.update(updateSQL);
}
公共列表返回结果(){
调试(“开始返回结果…”);
List=new ArrayList();
List rows=this.queryForList(getQuerySQL());
计数器=0;
用于(地图行:行){
捐赠d=新捐赠();
d、 setDonationID((长)行.get(“捐赠id”);
d、 setCCTransactionNumber((字符串)行.get(“txn_id”);
d、 setProgramCode((字符串)row.get(“gl_代码”);
d、 setLastName((字符串)row.get(“账单姓氏”);
d、 setFirstName((String)row.get(“账单名”);
d、 setAmount((字符串)row.get(“mc_gross”);
d、 setAddressLine1((字符串)行.get(“billing_street1”);
d、 setAddressLine2((字符串)row.get(“billing_street2”);
d、 setCity((String)row.get(“billing_city”);
d、 setState((字符串)row.get(“区域代码”);
d、 setZipCode((String)row.get(“账单邮政编码”);
d、 setCountry((String)row.get(“country_name”);
增加(d);
计数器++;
}
log.debug(计数器+“已加载捐赠”);
归还捐款;
}
}
有人能告诉我如何将此更改为使用JNDI数据源吗。我是否还需要为数据库池提供JNDI服务??我们有JBoss AS7,里面有数据源,我可以从JBoss外部使用吗


谢谢

在网上搜索“jboss external jndi”时找到了这个


看来你在找什么。使用您喜爱的搜索引擎,您可以找到令人惊讶的内容;)

(首先看一个JNDI教程并提出一个方法/代码。然后,如果还有问题,他们可能会提出一个更好的问题。)你能给我指一个好的JNDI教程吗?不要使用JNDI。但第一步是搜索。当然,你会得到很多垃圾,但也有很多宝石。这个阶段不是掌握,而是熟悉。如果它产生的问题比它回答的问题多,那其实也不错——这些问题本身会更具体,并且可以单独关注。此外,这篇文章似乎有点不清楚。通过JNDI使用/获取JDBC数据源(如果是,从何处获取)或完全切换到[不同的/JNDI]数据源(如果是,是什么)?即使是像前一个问题那样具体的问题,也会有足够的细化使之成为一个更好的问题(可能是重复的问题)。请参见此处: