spring启动googlesql不能正常工作

lc8prwob  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(376)

我已经开发了一个spring引导应用程序,可以在googleappengine上运行,使用googlesql及其在localperfect中的工作方式。当我部署应用程序和其他url时,它会工作一段时间,一个小时后,我会得到以下结果。将代码部署到googleappengine后,我可以从数据库中获取记录,但一小时后就不会获取记录了。我使用的是SpringBootVersion2.0.0.release和Java8
错误

org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution

这些是我正在使用pom.xml的配置

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.6.2</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.4.1</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.google.cloud.sql/mysql-socket-factory -->
        <dependency>
            <groupId>com.google.cloud.sql</groupId>
            <artifactId>mysql-socket-factory</artifactId>
            <version>1.0.5</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/commons-net/commons-net -->
        <dependency>
            <groupId>commons-net</groupId>
            <artifactId>commons-net</artifactId>
            <version>3.6</version>
        </dependency>
        <dependency>
            <groupId>com.google.api-client</groupId>
            <artifactId>google-api-client</artifactId>
            <version>1.21.0</version>
        </dependency>

    </dependencies>

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.0.0.RELEASE</version>
            </plugin>
            <!-- [START cloudplugin] -->
            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>1.3.1</version>
            </plugin>
            <!-- [END cloudplugin] -->

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>versions-maven-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>display-dependency-updates</goal>
                            <goal>display-plugin-updates</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <excludes>
                        <exclude>javax.servlet:javax.servlet-api</exclude>
                        <exclude>com.google.guava:guava</exclude> <!-- avoid android version -->
                    </excludes>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>

        </plugins>
    </build>

应用程序属性

spring.datasource.url=jdbc:mysql://google/fbconferencebot?cloudSqlInstance=conference:us-central1:appconference&socketFactory=com.google.cloud.sql.mysql.SocketFactory&user=root&password=*****

spring.jpa.hibernate.ddl-auto=none
spring.datasource.username=root
spring.datasource.password=*******
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.database=MYSQL
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
k97glaaz

k97glaaz1#

如果没有更详细的堆栈跟踪很难判断,但是您应该替换hibernate的连接池,因为它不适用于生产环境。这将处理底层连接。这里有一个很好的关于配置hikaricp w/spring引导的答案。
另外,您应该看看mike提到的springbootcloudsql启动程序——它包括hikaricp作为一个依赖项。

相关问题