当前位置: 首页 > 知识库问答 >
问题:

Spring Boot-外部tomcat服务器上的JDBC连接问题

佴普松
2023-03-14

我已经创建了一个Spring Boot应用程序,并将其作为WAR文件部署在外部Tomcat服务器上。

#spring.datasource.platform=mysql
#spring.datasource.url=jdbc:mysql://a.b.c.d/dbname
#spring.datasource.username=user
#spring.datasource.password=password
spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource
spring.datasource.tomcat.initial-size=15 
spring.datasource.tomcat.max-wait=20000 
spring.datasource.tomcat.max-active=50 
spring.datasource.tomcat.max-idle=15 
spring.datasource.tomcat.min-idle=8 
spring.datasource.tomcat.default-auto-commit=true 
spring.datasource.tomcat.test-on-borrow=false
<properties>
        <java.version>1.8</java.version>
    </properties>

    <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>

        <!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-jdbc -->
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-jdbc</artifactId>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-rest-hal-browser</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-batch -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-batch</artifactId>
            <version>2.1.8.RELEASE</version>
        </dependency>


        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-jasper -->
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-jasper</artifactId>
            <version>9.0.17</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.webjars/jquery -->
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>3.3.1-1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.webjars/jquery-ui -->



        <!-- https://mvnrepository.com/artifact/org.webjars/bootstrap -->
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>4.3.1</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>

        </dependency>

        <!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>6.0.10.Final</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/javax.el/javax.el-api -->
        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>javax.el-api</artifactId>
            <version>3.0.1-b06</version>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery-ui</artifactId>
            <version>1.12.1</version>
        </dependency>

        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
        </dependency>


        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-csv -->
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-csv</artifactId>
            <version>2.9.9</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.velocity/velocity -->
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity</artifactId>
            <version>1.7</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <executable>true</executable>
                </configuration>

                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <id>xjc</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <generatePackage>com.lasalle.soldierssoap</generatePackage>
                    <schemaDirectory>${project.basedir}/src/main/resources/</schemaDirectory>
                    <outputDirectory>${project.basedir}/src/main/java</outputDirectory>
                    <clearOutputDir>false</clearOutputDir>
                </configuration>
            </plugin>

        </plugins>


    </build>

</project>
<ResourceLink name="jdbc/testDB"
                global="jdbc/testDB"
                auth="Container"
                type="javax.sql.DataSource" />
<Resource name="jdbc/MyDB" 
      global="jdbc/testDB" 
      auth="Container" 
      type="javax.sql.DataSource" 
      driverClassName="com.mysql.jdbc.Driver" 
      url="jdbc:mysql://a.b.c.d:3306/dbname" 
      username="user" 
      password="password" 
      maxActive="100" 
      maxIdle="20" 
      minIdle="5" 
      maxWait="10000"/>

共有1个答案

洪楚
2023-03-14

在application.property文件中添加以下内容。

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/database_name?createDatabaseIfNotExist=true&useSSL=false
jdbc.user=root
jdbc.pass=1234

# hibernate.X
hibernate.dialect=org.hibernate.dialect.MySQL57Dialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=update
hibernate.cache.use_second_level_cache=true
hibernate.format_sql=true

#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/schoolmgt?createDatabaseIfNotExist=true
spring.datasource.username=root
spring.datasource.password=1234
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
server.error.whitelabel.enabled=false

希望这些对你有用。

 类似资料:
  • 我想用maven部署一个小型Web应用程序。我下载并配置了tomcat,并告诉IntelliJ在Run/Debug config中使用它,如下所示。我还将其配置为构建神器“战争爆炸”。 问题是,每次我运行项目时,都会出现一个错误,即: 工件JDBCTest:war:服务器未连接。部署不可用。 这是我的带有错误日志的dropbox,pom。xml、servlet类等。 我真的需要一些建议。

  • 本文向大家介绍使用phpMyAdmin连接到外部服务器,包括了使用phpMyAdmin连接到外部服务器的使用技巧和注意事项,需要的朋友参考一下 下面的代码行可以添加到底部的/etc/phpmyadmin/config.inc.php文件中- 它将显示“当前服务器:”,并同时下拉“ 127.0.0.1”和$cfg ['Servers'] [$i] ['host']提供的下拉列表。 用户可以在两个服务

  • 我需要一些帮助来理解如何编写HTTP路由器,它将HTTP标头识别为路由标准。我找到了链接https://github.com/cgbystrom/netty-tools/blob/master/src/main/java/se/cgbystrom/netty/http/router/RouterHandler.java它似乎自己做路由。但是现在不清楚,如何 连接到另一个HTTP服务器 发送HTTP

  • 问题内容: 在我的 主服务器上 ,我从可通过api访问的外部/单独的 redis服务器中 获取数据 。但是,api是不安全的。而且由于我希望将 Redis服务器 分开,因此该技术不适合我的情况。 在我来说,我想有2台独立的服务器, 一个 和 乙 。 A 应该在不使用api或url调用的情况下从 B 加载数据…而是应使用 port (例如)。这样,服务器 乙 只能从访问的 一个 。 我希望这种方法适

  • 我在springboot应用程序中有筛选器。在embedded tomcate 9.0.34中运行该应用程序时,它可以正常工作。然而,当我创建war并将其部署在外部Tomcate8.5上时,它会抛出以下错误。