有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Springboot+tomcat+ssh=连接链路故障

我正在尝试将spring boot应用程序部署到tomcat(我正在尝试7.0.858.5.29版本)
我们正在创建ssh隧道来连接远程数据库,如下所示:Spring Boot SSH Mysql?(contextListener,创建ssh连接)
当嵌入tomcat时,一切都正常工作,但当我尝试部署时,连接链路出现故障
以下是我的主要应用程序类:

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    private static final Logger LOGGER = Logger.getLogger(Application.class.getName());

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
         return application.sources(Application.class);
    }


    public static void main(String[] args) {
        SpringApplication.run(Application.class);
    }

    @Bean
    public ContextListener getListener() {
        return new ContextListener();
    }

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        servletContext.addListener(getListener());
        super.onStartup(servletContext);
    }

 }

和聚甲醛的碎片。xml:

...   
<packaging>war</packaging>

<properties>
    <main.basedir>${project.parent.basedir}</main.basedir>
</properties>
...
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <version>1.3.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>6.0.6</version>
    </dependency>
    <dependency>
        <groupId>com.jcraft</groupId>
        <artifactId>jsch</artifactId>
        <version>0.1.54</version>
    </dependency>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20180130</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    ...
</dependencies>

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

应用程序。特性:

server.contextPath=/app
spring.datasource.url=jdbc:mysql://localhost:3307/db
spring.datasource.username=user
spring.datasource.password=pass
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.show-sql=true
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl  

错误如下:

2018-03-25 00:41:29.507 ERROR 19924 --- [ost-startStop-1] o.a.tomcat.jdbc.pool.ConnectionPool      : Unable to create initial connections of pool.

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

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.  

我读了很多关于如何将warwithspringboot应用程序部署到tomcat的教程(如https://www.mkyong.com/spring-boot/spring-boot-deploy-war-file-to-tomcat/)。我已经做了所有的事情,但仍然得到这个错误

我尝试了很多很多解决方案,但没有任何帮助,以下是我的步骤:

I.添加不同的属性,如:

spring.datasource.tomcat.initialSize=5
spring.datasource.tomcat.maxActive=55
spring.datasource.tomcat.maxIdle=21
spring.datasource.tomcat.minIdle=13
spring.datasource.tomcat.testWhileIdle=true
spring.datasource.tomcat.timeBetweenEvictionRunsMillis=34000
spring.datasource.tomcat.minEvictableIdleTimeMillis=55000
spring.datasource.tomcat.validationInterval=34000
spring.datasource.tomcat.testOnBorrow=true
spring.datasource.tomcat.validationQuery=SELECT 1
spring.datasource.tomcat.removeAbandoned=true
spring.datasource.tomcat.removeAbandonedTimeout=233  

二,。像这里一样使用Tomcat JDBC并设置连接池:Not able to set spring.datasource.type

III.检查所有内容,在回答此帖子时指出:Solving a "communications link failure" with JDBC and MySQL

四、更换卡塔琳娜。增加补助金的政策,如下:access denied when trying to connect to mysql using tomcat datasource

当前,我恢复了服务器中的所有更改。xml它看起来是这样的:

<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <Listener className="org.apache.catalina.core.JasperListener" />
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
  <GlobalNamingResources>
      <Resource name="UserDatabase" auth="Container"
          type="org.apache.catalina.UserDatabase"
          description="User database that can be updated and saved"
          factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
          pathname="conf/tomcat-users.xml" />
   </GlobalNamingResources>
   <Service name="Catalina">
      <Executor name="tomcatThreadPool" namePrefix="catalina-exec maxThreads="150" minSpareThreads="4"/>
      <Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />
      <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
      <Engine name="Catalina" defaultHost="localhost">
         <Realm className="org.apache.catalina.realm.LockOutRealm">
         <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
           resourceName="UserDatabase"/>
         </Realm>
         <Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log." suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />
         </Host>
      </Engine>
 </Service>

我在搜索信息,如何在这个xml上正确设置ssh连接,但我没有找到任何对我有帮助的东西

我做错了什么?我错过什么了吗?有没有关于如何使用数据库(或ssh)将war部署到tomcat的完整教程


共 (0) 个答案