GAE spring hibernate应用程序的问题

时间:2014-08-12 12:27:08

标签: java hibernate google-app-engine maven google-cloud-sql

感谢您光临我的问题。

我有一个使用云SQL在Google云上运行的java(Spring + maven + hibernate)应用程序。每当数据库和应用程序之间存在通信时,它就会抛出这个异常,说无法打开连接通信失败。在最后它给了我:

Caused by: java.net.SocketException: Permission denied: Attempt to access a blocked recipient without permission. (mapped-IPv4)
    at com.google.appengine.api.socket.SocketApiHelper.translateError(SocketApiHelper.java:105)
    at com.google.appengine.api.socket.SocketApiHelper.translateError(SocketApiHelper.java:116)
    at com.google.appengine.api.socket.SocketApiHelper.makeSyncCall(SocketApiHelper.java:82)
    at com.google.appengine.api.socket.AppEngineSocketImpl.createSocket(AppEngineSocketImpl.java:497)
    at com.google.appengine.api.socket.AppEngineSocketImpl.connectToAddress(AppEngineSocketImpl.java:362)
    at com.google.appengine.api.socket.AppEngineSocketImpl.connect(AppEngineSocketImpl.java:352)
    at java.net.Socket.connect(Socket.java:600)
    at java.net.Socket.connect(Socket.java:537)
    at java.net.Socket.<init>(Socket.java:434)
    at java.net.Socket.<init>(Socket.java:250)
    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:259)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:300)
    ... 113 more

org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Could not open connection
    at org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:440)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:334)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at com.sun.proxy.$Proxy38.loadAdminLoginFromDetails(Unknown Source)
    at com.bullbeardevice.service.impl.CustomAuthenticationManager.authenticate(CustomAuthenticationManager.java:47)

我的hibernate配置文件:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
        xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
            http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

<context:component-scan base-package="com.bullbeardevice.*" /> 


  <!-- Hibernate Session Factory -->
<bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:database.properties</value>
            </list>
        </property>
    </bean>

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

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="com.abc.model" />
        <property name="hibernateProperties">
            <props>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="hibernate.jdbc.batch_size">100</prop>
                <!-- <prop key="hibernate.hbm2ddl.auto">create-drop</prop>  -->
                <prop key="hibernate.current_session_context_class">
                    org.springframework.orm.hibernate4.SpringSessionContext
                </prop>
                <!-- configuration pool via c3p0 -->
                <prop key="hibernate.c3p0.acquire_increment">5</prop>
                <prop key="hibernate.c3p0.idle_test_period">600</prop>
                <prop key="hibernate.c3p0.max_size">25</prop>
                <prop key="hibernate.c3p0.max_statements">25</prop>
                <prop key="hibernate.c3p0.min_size">5</prop>
                <prop key="hibernate.c3p0.timeout">300</prop>
                <prop key="hibernate.connection.release_mode">auto</prop>
                <prop key="hibernate.auto_close_session">true</prop>
            </props>
        </property>
    </bean>
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
  <tx:annotation-driven transaction-manager="transactionManager"/>
  </beans>

我的database.properties:

#db.driverClassName=com.mysql.jdbc.Driver
db.driverClassName=com.mysql.jdbc.GoogleDriver
db.url=jdbc:google:mysql://xxx:xxx/xxxx
#db.url=jdbc:Oracle:thin:@127.0.0.1:1521/XE
db.username=root
db.password=abc
#hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.cache.use_second_level_cache=false
hibernate.cache.use_query_cache=false
#hibernate.cache.provider_class=net.sf.ehcache.hibernate.EhCacheProvider
#hibernate.cache.provider_class==org.hibernate.cache.EhCacheProvider
#db.sid=XE
# configuration for hibernate search
hibernate.search.default.locking_strategy=simple
#hibernate.search.analyzer=org.apache.lucene.analysis.en.EnglishAnalyzer
hibernate.search.worker.batch_size=100
hibernate.search.indexing_strategy = manual
hibernate.search.default.reader.strategy = shared
hibernate.search.default.worker.thread_pool.size=30
hibernate.search.default.indexwriter.ram_buffer_size=10
hibernate.search.default.indexwriter.merge_max_optimize_size=7
hibernate.search.default.indexwriter.merge_max_size=7

请帮我解决这个问题。我从上周开始就被困住了。

0 个答案:

没有答案