0

我在这里粘贴了完整的堆栈跟踪 - Pastebin

Caused by: java.security.AccessControlException: access denied (java.net.SocketPermission localhost resolve)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
    at java.security.AccessController.checkPermission(AccessController.java:546)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
    at 

    com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkPermission(DevAppServerFactory.java:283)
        at java.lang.SecurityManager.checkConnect(SecurityManager.java:1031)
        at java.net.InetAddress.getAllByName0(InetAddress.java:1145)
        at java.net.InetAddress.getAllByName(InetAddress.java:1083)
        at java.net.InetAddress.getAllByName(InetAddress.java:1019)
        at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:243)
        at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:284)
        at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2043)
        ... 123 more
    Caused by:

    com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

这是我的数据库属性

jdbc.driverClassName=com.google.appengine.api.rdbms.AppEngineDriver
jdbc.url=jdbc:mysql://localhost:3306/tester
jdbc.username=root
jdbc.password=root
hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
hibernate.hbm2ddl.auto=update

和 applicationContext -

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location">
      <value>/WEB-INF/classes/database.properties</value>
    </property>
  </bean>

  <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${jdbc.driverClassName}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
  </bean>

  <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource">
      <ref local="dataSource"/>
    </property>

    <property name="hibernateProperties">
      <props>
        <prop key="hibernate.dialect">${hibernate.dialect}</prop>
        <prop key="hibernate.show_sql">false</prop>
        <prop key="hibernate.cache.use_query_cache">
          false
        </prop>
        <prop key="hibernate.cache.use_second_level_cache">
          false
        </prop>
        <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
      </props>
    </property>

这是我尝试使用它的方式 -

public class MainDao {
  protected SessionFactory sessionFactory;

  public SessionFactory getSessionFactory() {
    return sessionFactory;
  }

  public void setSessionFactory(SessionFactory sessionFactory) {
    this.sessionFactory = sessionFactory;
  }

  private Session openSession(){
    return this.sessionFactory.openSession();
  }
}

调用 openSession 时出现错误。需要帮助。我无法弄清楚问题所在。

4

1 回答 1

0

我通过将数据库属性更改为这些来解决问题

jdbc.driverClassName=com.google.appengine.api.rdbms.AppEngineDriver
jdbc.url=jdbc:google:rdbms://localhost/database
jdbc.username=root
jdbc.password=root
hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
hibernate.hbm2ddl.auto=update

然后dev_appserver.cmd使用以下 jvm args 运行命令 -

-Drdbms.server=local
-Drdbms.driver=com.mysql.jdbc.Driver
-Drdbms.url=jdbc:mysql://localhost:3306/yourdatabase?user=username&password=password

这对我有用。命令提示符上的命令不起作用(显示错误),但在我的 IDE(intellij 想法)中,在将上面指定为 jvm 参数后它起作用了。

于 2012-11-02T08:17:20.980 回答