无法在我的其他电脑上运行相同的servlet / hibernate项目

时间:2015-10-20 08:04:42

标签: java mysql eclipse hibernate

我的项目在我的主计算机上没有任何投诉。我也使用bitbucket和sourcetree。在我的另一台计算机上,我将项目克隆到了我的eclipse工作区。当试图在eclipse中启动tomcat8服务器时,我开始出现一些错误,这似乎与hibernate和hibernate.cfg.xml中的mysql连接有关

我不知道是什么导致这种情况,因为它在我的其他电脑上工作正常。

的hibernate.cfg.xml

/**
 * Event dispatched when loading the layout
 * @param Varien_Event_Observer $observer
 */
public function coreLayoutUpdateUpdatesGetAfter($observer)
{
    /** @var Mage_Core_Model_Config_Element $updates */
    if (Mage::getStoreConfig('foobar/general/enabled')) {
        $file = Mage::getStoreConfig('foobar/general/layout_xml');
        if (!empty($file)) {
            $updates = $observer->getUpdates();
            if ($updates->foobar) {
                $updates->foobar->file = $file;
            }
        }
    }
}

Consolelog:

    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>

    <property name="connection.url">jdbc:mysql://databaseIP:PORT/Test</property>

    <property name="connection.username">databaseUser</property>

    <property name="connection.password">userpassword</property>

    <property name="c3p0.min_size">5</property>  
    <property name="c3p0.max_size">20</property>  
    <property name="c3p0.timeout">1800</property>  
    <property name="hibernate.c3p0.max_statements">50</property>
    <property name="hibernate.c3p0.idle_test_period">3000</property>

    <property name="connection.pool_size">50</property>

    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.enable_lazy_load_no_trans">true</property>
    <property name="current_session_context_class">thread</property>
    <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
    <property name="show_sql">false</property>
    <property name="hbm2ddl.auto">update</property>

    <mapping class="com.Test.class1"/>
    <mapping class="com.Test.class2"/>
    <mapping class="com.Test.class3"/>

2 个答案:

答案 0 :(得分:0)

检查您的MySQL设置,它拒绝从您的其他PC的IP地址登录。问题可能是MySQL未设置为完全允许来自其他PC的连接,或者您使用的用户不允许从该IP登录。

请参阅https://dev.mysql.com/doc/refman/5.1/en/account-names.html

答案 1 :(得分:0)

你可以检查两件事。

如果提供的密码是有效的。

授予该用户访问数据库的权限。

grant all privileges on mydb.* to databaseUser@'%' identified by 'userpassword';

%是一个通配符,它​​授予访问任何IP的权限 - 您也可以执行&#39;%。domain.com&#39;或者&#39;%。123.123.123&#39;如果你需要,还有类似的东西。